Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
go-orusapi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
orus-io
go-orusapi
Commits
5dc9b01039ff
Commit
5dc9b01039ff
authored
3 years ago
by
Florent Aide
Browse files
Options
Downloads
Patches
Plain Diff
fix ConfigureAPI signature according to cmd/serve.go template
parent
9f520041a3cc
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
templates/server/cmdCustomInfo.gotmpl
+1
-1
1 addition, 1 deletion
templates/server/cmdCustomInfo.gotmpl
templates/server/cmdServeConfig.gotmpl
+1
-0
1 addition, 0 deletions
templates/server/cmdServeConfig.gotmpl
templates/server/configureapi.gotmpl
+17
-1
17 additions, 1 deletion
templates/server/configureapi.gotmpl
with
19 additions
and
2 deletions
templates/server/cmdCustomInfo.gotmpl
+
1
−
1
View file @
5dc9b010
...
...
@@ -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"`
}
This diff is collapsed.
Click to expand it.
templates/server/cmdServeConfig.gotmpl
+
1
−
0
View file @
5dc9b010
...
...
@@ -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
}
This diff is collapsed.
Click to expand it.
templates/server/configureapi.gotmpl
+
17
−
1
View file @
5dc9b010
...
...
@@ -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,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment