Skip to content

Instantly share code, notes, and snippets.

@preslavmihaylov
Last active April 12, 2020 11:09
Show Gist options
  • Save preslavmihaylov/9f9547f1cb66d43cad8be89b7ddd9b26 to your computer and use it in GitHub Desktop.
Save preslavmihaylov/9f9547f1cb66d43cad8be89b7ddd9b26 to your computer and use it in GitHub Desktop.
package bundlefx
// imports
func registerHooks(
lifecycle fx.Lifecycle,
logger *zap.SugaredLogger, cfg *configfx.Config, mux *http.ServeMux,
) {
lifecycle.Append(
fx.Hook{
OnStart: func(context.Context) error {
logger.Info("Listening on ", cfg.ApplicationConfig.Address)
go http.ListenAndServe(cfg.ApplicationConfig.Address, mux)
return nil
},
OnStop: func(context.Context) error {
return logger.Sync()
},
},
)
}
// Module provided to fx
var Module = fx.Options(
configfx.Module,
loggerfx.Module,
httpfx.Module,
fx.Invoke(registerHooks),
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment