diff --git a/templates/server/configureapi.gotmpl b/templates/server/configureapi.gotmpl index db5348b25dc17b8ec84d20f9b793b293e3a3a6e7_dGVtcGxhdGVzL3NlcnZlci9jb25maWd1cmVhcGkuZ290bXBs..73aff05670f0014d5881b79fb11be9dadd253c39_dGVtcGxhdGVzL3NlcnZlci9jb25maWd1cmVhcGkuZ290bXBs 100644 --- a/templates/server/configureapi.gotmpl +++ b/templates/server/configureapi.gotmpl @@ -22,9 +22,12 @@ {{ imports .Imports }} ) +// Callback is a simple function +type Callback func() + // Config holds the things required to configure the API type Config struct { Log zerolog.Logger DB *sqlx.DB BaseURL string @@ -25,9 +28,10 @@ // Config holds the things required to configure the API type Config struct { Log zerolog.Logger DB *sqlx.DB BaseURL string + Shutdown []Callback // Here you can add anything the ConfigureAPI function will need to setup // the API } @@ -56,6 +60,8 @@ type ConfiguredAPI struct { api *{{.Package}}.{{ pascalize .Name }}API handler http.Handler + + config Config } func (capi *ConfiguredAPI) Name() string { @@ -70,6 +76,10 @@ } func (capi *ConfiguredAPI) ServerShutdown() { + lsize := len(capi.config.Shutdown) + for i := range capi.config.Shutdown { + capi.config.Shutdown[lsize-i-1]() + } } func ConfigureAPI(api *{{.Package}}.{{ pascalize .Name }}API, server *orusapi.Server, config Config) (*ConfiguredAPI, error) { @@ -168,6 +178,7 @@ return &ConfiguredAPI{ api: api, handler: setupGlobalMiddleware(api.Serve(setupMiddlewares)), + config: config, }, nil }