config: added base.host and base.path settings

This commit is contained in:
Steffen Vogel 2019-11-13 20:52:27 +01:00
parent e33c797012
commit 085627f4e7
2 changed files with 20 additions and 11 deletions

View file

@ -22,6 +22,8 @@ func InitConfig() *config.Config {
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)")
basePath = flag.String("base-path", "/api/v2", "The path at which the API routes are located (default /api/v2)")
)
flag.Parse()
@ -33,14 +35,16 @@ func InitConfig() *config.Config {
}
static := map[string]string{
"db.host": *dbHost,
"db.name": *dbName,
"db.user": *dbUser,
"db.pass": *dbPass,
"db.init": dbInitStr,
"db.ssl": *dbSSLMode,
"amqp.url": *amqpURL,
"mode": *mode,
"db.host": *dbHost,
"db.name": *dbName,
"db.user": *dbUser,
"db.pass": *dbPass,
"db.init": dbInitStr,
"db.ssl": *dbSSLMode,
"amqp.url": *amqpURL,
"mode": *mode,
"base.host": *baseHost,
"base.path": *basePath,
}
mappings := map[string]string{
@ -51,6 +55,8 @@ func InitConfig() *config.Config {
"DB_SSLMOE": "db.ssl",
"DB_INIT": "db.init",
"AMQP_URL": "amqp.url",
"BASE_HOST": "base.host",
"BASE_PATH": "base.path",
}
defaults := config.NewStatic(static)

View file

@ -16,7 +16,6 @@ import (
docs "git.rwth-aachen.de/acs/public/villas/web-backend-go/doc/api" // doc/api folder is used by Swag CLI, you have to import it
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/dashboard"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/file"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/metrics"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/scenario"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/signal"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/simulationmodel"
@ -34,7 +33,6 @@ import (
// @contact.email sonja.happ@eonerc.rwth-aachen.de
// @license.name GNU GPL 3.0
// @license.url http://www.gnu.de/documents/gpl-3.0.en.html
// @host villas-new.k8s.fein-aachen.org
// @BasePath /api/v2
func main() {
log.Println("Starting VILLASweb-backend-go")
@ -48,9 +46,14 @@ func main() {
gin.SetMode(gin.ReleaseMode)
}
baseHost, _ := c.Config.String("base.host")
basePath, _ := c.Config.String("base.path")
docs.SwaggerInfo.Host = baseHost
docs.SwaggerInfo.BasePath = basePath
r := gin.Default()
api := r.Group("/api/v2")
api := r.Group(basePath)
// All endpoints require authentication except when someone wants to
// login (POST /authenticate)