Skip to content

Commit

Permalink
feat: added shutdown method in app template (#22)
Browse files Browse the repository at this point in the history
ISSUE: ServiceWeaver/weaver#275

A method to shut down the app/component was implemented in Service
Weaver
and then we implemented it here.
  • Loading branch information
renanbastos93 committed Jun 8, 2024
2 parents 8b2422d + 69142d4 commit c4f6f5b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion internal/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"
)

const Version = "v0.5.2"
const Version = "v0.5.3"

func ValidateLatestVersion() {
cmd := exec.Command("go", "list", "-m", "github.com/renanbastos93/boneless@latest")
Expand Down
10 changes: 9 additions & 1 deletion templates/files/component.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ type Config struct {
type implapp struct {
weaver.Implements[Component]
weaver.WithConfig[Config]
db *store.Queries
dbConn *sql.DB
db *store.Queries
}

func (e *implapp) Init(ctx context.Context) error {
Expand All @@ -44,10 +45,17 @@ func (e *implapp) Init(ctx context.Context) error {
return fmt.Errorf("failed to ping: %w", err)
}

e.dbConn = db
e.db = store.New(db)
return nil
}


func (e *implapp) Shutdown(ctx context.Context) error {
// TODO: create your logic to shutdown the component
return e.dbConn.Close()
}

func (e implapp) AllExamples(ctx context.Context) (out AllExamplesOut, err error) {
examples, err := e.db.ListExamples(ctx)
if err != nil {
Expand Down

0 comments on commit c4f6f5b

Please sign in to comment.