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

fix ConfigureAPI signature according to cmd/serve.go template

parent 9f520041a3cc
No related branches found
No related tags found
No related merge requests found
......@@ -4,5 +4,5 @@
type CustomInfo struct {
// Custom global flags can be added here. For example:
// BaseURL string `long:"base-url" env:"BASE_URL" ini-name:"base-url" description:"The public facing base URL of the API. Used to forge URLs"`
BaseURL string `long:"base-url" env:"BASE_URL" ini-name:"base-url" description:"The public facing base URL of the API. Used to forge URLs"`
}
......@@ -7,6 +7,7 @@
}
func setupServeConfig(config *restapi.Config) error {
config.BaseURL = InfoOptions.BaseURL
// This is where the api config can be customized at will
return nil
}
......@@ -16,6 +16,7 @@
"github.com/go-openapi/runtime"
"github.com/go-openapi/runtime/middleware"
"github.com/go-openapi/runtime/security"
"orus.io/orus-io/go-orusapi"
{{ imports .DefaultImports }}
{{ imports .Imports }}
......@@ -26,6 +27,7 @@
Log zerolog.Logger
DB *sqlx.DB
BaseURL string
// Here you can add anything the ConfigureAPI function will need to setup
// the API
}
......@@ -70,7 +72,7 @@
func (capi *ConfiguredAPI) ServerShutdown() {
}
func ConfigureAPI(api *{{.Package}}.{{ pascalize .Name }}API, config Config) (*ConfiguredAPI, error) {
func ConfigureAPI(api *{{.Package}}.{{ pascalize .Name }}API, server *orusapi.Server, config Config) (*ConfiguredAPI, error) {
// configure the api here
api.ServeError = errors.ServeError
......@@ -74,6 +76,16 @@
// configure the api here
api.ServeError = errors.ServeError
if config.BaseURL == "" {
scheme := "https"
if len(server.EnabledListeners) != 0 {
scheme = server.EnabledListeners[0]
}
config.BaseURL = fmt.Sprintf("%s://%s:%d",
scheme, server.Host, server.Port,
)
}
// Set your custom logger if needed. Default one is log.Printf
// Expected interface func(string, ...interface{})
//
......@@ -148,6 +160,10 @@
})
}
{{- end }}
if server.Prometheus {
api.PrometheusInstrumentHandlers()
}
api.LoggingInstrumentHandlers()
return &ConfiguredAPI{
api: api,
......
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