Last active
April 12, 2020 07:30
-
-
Save presmihaylov/02bdd10e6bbee1b1df0d6b59b44f753b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
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