Skip to content
Snippets Groups Projects
Commit 73aff05670f0 authored by Florent Aide's avatar Florent Aide
Browse files

tmpl: add shutdown callbacks in generated config

parent db5348b25dc1
No related branches found
No related tags found
No related merge requests found
Pipeline #31078 failed
......@@ -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
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment