separate port and host configuration parameters (default values remain unchanged)

This commit is contained in:
Sonja Happ 2019-11-19 15:35:21 +01:00
parent 9deed119fd
commit 3524564a0f
3 changed files with 12 additions and 3 deletions

View file

@ -12,6 +12,7 @@ variables:
RABBITMQ_DEFAULT_USER: villas
RABBITMQ_DEFAULT_PASS: villas
AMQPURL: 'amqp://villas:villas@rabbitmq:5672'
PORT: 4000
stages:
- prepare

View file

@ -25,7 +25,8 @@ func InitConfig() error {
amqpURL = flag.String("amqp", "", "If set, use this url to connect to an AMQP broker (default is disabled)")
configFile = flag.String("configFile", "", "Path to YAML configuration file")
mode = flag.String("mode", "release", "Select debug/release/test mode (default is release)")
baseHost = flag.String("base-host", "localhost:4000", "The host:port at which the backend is hosted (default: localhost:4000)")
port = flag.String("port", "4000", "Port of the backend (default is 4000)")
baseHost = flag.String("base-host", "localhost", "The host at which the backend is hosted (default: localhost)")
basePath = flag.String("base-path", "/api/v2", "The path at which the API routes are located (default /api/v2)")
)
flag.Parse()
@ -38,6 +39,7 @@ func InitConfig() error {
"db.ssl": *dbSSLMode,
"amqp.url": *amqpURL,
"mode": *mode,
"port": *port,
"base.host": *baseHost,
"base.path": *basePath,
}
@ -52,6 +54,7 @@ func InitConfig() error {
"BASE_HOST": "base.host",
"BASE_PATH": "base.path",
"MODE": "mode",
"PORT": "port",
}
defaults := config.NewStatic(static)

View file

@ -69,8 +69,13 @@ func main() {
log.Printf("Error reading base.path from global configuration: %v, aborting.", err.Error())
return
}
port, err := configuration.GolbalConfig.String("port")
if err != nil {
log.Printf("Error reading port from global configuration: %v, aborting.", err.Error())
return
}
apidocs.SwaggerInfo.Host = baseHost
apidocs.SwaggerInfo.Host = baseHost + ":" + port
apidocs.SwaggerInfo.BasePath = basePath
metrics.InitCounters(db)
@ -129,5 +134,5 @@ func main() {
log.Printf("Connected AMQP client to %s", amqpurl)
}
// server at port 4000 to match frontend's redirect path
r.Run(":4000")
r.Run(":" + port)
}