diff --git a/templates/server/cmdCustomInfo.gotmpl b/templates/server/cmdCustomInfo.gotmpl index 9f520041a3cc14320375bbaad4aaaa9f9185ccdb_dGVtcGxhdGVzL3NlcnZlci9jbWRDdXN0b21JbmZvLmdvdG1wbA==..5dc9b01039ffcda7996da415b7a6e3e5485d5b21_dGVtcGxhdGVzL3NlcnZlci9jbWRDdXN0b21JbmZvLmdvdG1wbA== 100644 --- a/templates/server/cmdCustomInfo.gotmpl +++ b/templates/server/cmdCustomInfo.gotmpl @@ -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"` } diff --git a/templates/server/cmdServeConfig.gotmpl b/templates/server/cmdServeConfig.gotmpl index 9f520041a3cc14320375bbaad4aaaa9f9185ccdb_dGVtcGxhdGVzL3NlcnZlci9jbWRTZXJ2ZUNvbmZpZy5nb3RtcGw=..5dc9b01039ffcda7996da415b7a6e3e5485d5b21_dGVtcGxhdGVzL3NlcnZlci9jbWRTZXJ2ZUNvbmZpZy5nb3RtcGw= 100644 --- a/templates/server/cmdServeConfig.gotmpl +++ b/templates/server/cmdServeConfig.gotmpl @@ -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 } diff --git a/templates/server/configureapi.gotmpl b/templates/server/configureapi.gotmpl index 9f520041a3cc14320375bbaad4aaaa9f9185ccdb_dGVtcGxhdGVzL3NlcnZlci9jb25maWd1cmVhcGkuZ290bXBs..5dc9b01039ffcda7996da415b7a6e3e5485d5b21_dGVtcGxhdGVzL3NlcnZlci9jb25maWd1cmVhcGkuZ290bXBs 100644 --- a/templates/server/configureapi.gotmpl +++ b/templates/server/configureapi.gotmpl @@ -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,