Skip to content

Instantly share code, notes, and snippets.

@presmihaylov
Last active April 12, 2020 07:30
Show Gist options
  • Save presmihaylov/02bdd10e6bbee1b1df0d6b59b44f753b to your computer and use it in GitHub Desktop.
Save presmihaylov/02bdd10e6bbee1b1df0d6b59b44f753b to your computer and use it in GitHub Desktop.
...
func main() {
fx.New(
...
fx.Invoke(registerHooks),
).Run()
}
func registerHooks(
lifecycle fx.Lifecycle,
logger *zap.SugaredLogger, cfg *Config, mux *http.ServeMux,
) {
lifecycle.Append(
fx.Hook{
OnStart: func(context.Context) error {
go http.ListenAndServe(cfg.ApplicationConfig.Address, mux)
return nil
},
OnStop: func(context.Context) error {
return logger.Sync()
},
},
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment