Last active
April 12, 2020 11:09
-
-
Save preslavmihaylov/9f9547f1cb66d43cad8be89b7ddd9b26 to your computer and use it in GitHub Desktop.
This file contains 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
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