Skip to content

Commit

Permalink
refactor: fx lifecycle parameter name
Browse files Browse the repository at this point in the history
  • Loading branch information
joaofnds committed Jan 9, 2024
1 parent 3fbf89a commit 53fff9b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
4 changes: 2 additions & 2 deletions adapter/http/fiber.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ func NewFiber(config Config, probe Probe) *fiber.App {
return app
}

func HookFiber(lc fx.Lifecycle, app *fiber.App, config Config) {
lc.Append(fx.Hook{
func HookFiber(lifecycle fx.Lifecycle, app *fiber.App, config Config) {
lifecycle.Append(fx.Hook{
OnStart: func(context.Context) error {
go func() {
if err := app.Listen(fmt.Sprintf(":%d", config.Port)); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions adapter/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ func NewServer(c Config) *Server {
return &http.Server{Addr: c.Addr}
}

func HookMetricsHandler(lc fx.Lifecycle, server *Server, logger *zap.Logger) {
lc.Append(fx.Hook{
func HookMetricsHandler(lifecycle fx.Lifecycle, server *Server, logger *zap.Logger) {
lifecycle.Append(fx.Hook{
OnStart: func(context.Context) error {
go func() {
err := server.ListenAndServe()
Expand Down
4 changes: 2 additions & 2 deletions adapter/mongo/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ func NewClient(ctx context.Context, config Config) (*mongo.Client, error) {
return mongo.Connect(ctx, clientOptions)
}

func HookConnection(lc fx.Lifecycle, client *mongo.Client, logger *zap.Logger) {
lc.Append(fx.Hook{
func HookConnection(lifecycle fx.Lifecycle, client *mongo.Client, logger *zap.Logger) {
lifecycle.Append(fx.Hook{
OnStart: func(ctx context.Context) error {
err := client.Ping(ctx, nil)
if err != nil {
Expand Down
11 changes: 9 additions & 2 deletions adapter/tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,19 @@ var Module = fx.Module(
return provider
}),

fx.Invoke(func(livecycle fx.Lifecycle, exporter *otlptrace.Exporter, provider *sdktrace.TracerProvider) {
livecycle.Append(fx.Hook{
fx.Invoke(func(
lifecycle fx.Lifecycle,
exporter *otlptrace.Exporter,
provider *sdktrace.TracerProvider,
) {
lifecycle.Append(fx.Hook{
OnStart: func(ctx context.Context) error {
return exporter.Start(ctx)
},
OnStop: func(ctx context.Context) error {
if err := exporter.Shutdown(ctx); err != nil {
return err
}
return provider.Shutdown(ctx)
},
})
Expand Down

0 comments on commit 53fff9b

Please sign in to comment.