mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
config: added base.host and base.path settings
This commit is contained in:
parent
e33c797012
commit
085627f4e7
2 changed files with 20 additions and 11 deletions
|
@ -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)")
|
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")
|
configFile = flag.String("configFile", "", "Path to YAML configuration file")
|
||||||
mode = flag.String("mode", "release", "Select debug/release/test mode (default is release)")
|
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()
|
flag.Parse()
|
||||||
|
|
||||||
|
@ -33,14 +35,16 @@ func InitConfig() *config.Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
static := map[string]string{
|
static := map[string]string{
|
||||||
"db.host": *dbHost,
|
"db.host": *dbHost,
|
||||||
"db.name": *dbName,
|
"db.name": *dbName,
|
||||||
"db.user": *dbUser,
|
"db.user": *dbUser,
|
||||||
"db.pass": *dbPass,
|
"db.pass": *dbPass,
|
||||||
"db.init": dbInitStr,
|
"db.init": dbInitStr,
|
||||||
"db.ssl": *dbSSLMode,
|
"db.ssl": *dbSSLMode,
|
||||||
"amqp.url": *amqpURL,
|
"amqp.url": *amqpURL,
|
||||||
"mode": *mode,
|
"mode": *mode,
|
||||||
|
"base.host": *baseHost,
|
||||||
|
"base.path": *basePath,
|
||||||
}
|
}
|
||||||
|
|
||||||
mappings := map[string]string{
|
mappings := map[string]string{
|
||||||
|
@ -51,6 +55,8 @@ func InitConfig() *config.Config {
|
||||||
"DB_SSLMOE": "db.ssl",
|
"DB_SSLMOE": "db.ssl",
|
||||||
"DB_INIT": "db.init",
|
"DB_INIT": "db.init",
|
||||||
"AMQP_URL": "amqp.url",
|
"AMQP_URL": "amqp.url",
|
||||||
|
"BASE_HOST": "base.host",
|
||||||
|
"BASE_PATH": "base.path",
|
||||||
}
|
}
|
||||||
|
|
||||||
defaults := config.NewStatic(static)
|
defaults := config.NewStatic(static)
|
||||||
|
|
9
start.go
9
start.go
|
@ -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
|
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/dashboard"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/file"
|
"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/scenario"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/signal"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/signal"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/simulationmodel"
|
"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
|
// @contact.email sonja.happ@eonerc.rwth-aachen.de
|
||||||
// @license.name GNU GPL 3.0
|
// @license.name GNU GPL 3.0
|
||||||
// @license.url http://www.gnu.de/documents/gpl-3.0.en.html
|
// @license.url http://www.gnu.de/documents/gpl-3.0.en.html
|
||||||
// @host villas-new.k8s.fein-aachen.org
|
|
||||||
// @BasePath /api/v2
|
// @BasePath /api/v2
|
||||||
func main() {
|
func main() {
|
||||||
log.Println("Starting VILLASweb-backend-go")
|
log.Println("Starting VILLASweb-backend-go")
|
||||||
|
@ -48,9 +46,14 @@ func main() {
|
||||||
gin.SetMode(gin.ReleaseMode)
|
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()
|
r := gin.Default()
|
||||||
|
|
||||||
api := r.Group("/api/v2")
|
api := r.Group(basePath)
|
||||||
|
|
||||||
// All endpoints require authentication except when someone wants to
|
// All endpoints require authentication except when someone wants to
|
||||||
// login (POST /authenticate)
|
// login (POST /authenticate)
|
||||||
|
|
Loading…
Add table
Reference in a new issue