From c8508a49762da5b8bab34e55a801e2e9e2936565 Mon Sep 17 00:00:00 2001 From: pb Date: Mon, 4 Dec 2023 14:46:36 +0100 Subject: [PATCH] Modified DCName and DBPoint retrieving --- main.go | 6 ++++-- routers/router.go | 2 -- services/init.go | 37 ++++++++++++++++++++++++++----------- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/main.go b/main.go index 8d13b38..5d3a37d 100644 --- a/main.go +++ b/main.go @@ -27,11 +27,13 @@ func main() { routers.Init() services.Init() + beego.BConfig.RunMode = "dev" + // if beego.BConfig.RunMode == "dev" { // // beego.BConfig.WebConfig.DirectoryIndex = true beego.BConfig.WebConfig.DirectoryIndex = true beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger" - + // } @@ -71,7 +73,7 @@ func loadConfig(){ o = onion.New(l1, l3) } - conf.GetConfig().MongoURL = o.GetStringDefault("MongoURL", "mongodb://127.0.0.1:27017/beego-demo") + conf.GetConfig().MongoURL = o.GetStringDefault("MongoURL", "mongodb://127.0.0.1:27017") conf.GetConfig().DCNAME = o.GetStringDefault("DCNAME", "DC_myDC") conf.GetConfig().DBPOINT = o.GetStringDefault("DBPOINT", "demdemo_06042021o") diff --git a/routers/router.go b/routers/router.go index 69adca3..58967f1 100644 --- a/routers/router.go +++ b/routers/router.go @@ -79,8 +79,6 @@ func Init() { ), ) - // Namespace containing useful Path such as ping - beego.AddNamespace(ns) diff --git a/services/init.go b/services/init.go index fdf63d4..3e54ce5 100644 --- a/services/init.go +++ b/services/init.go @@ -1,29 +1,44 @@ package services import ( - "os" + "cloud.o-forge.io/core/oc-catalog/conf" "github.com/beego/beego/v2/core/logs" - beego "github.com/beego/beego/v2/server/web" ) func Init() { - Discoveryinit() //First init DC name + // Discoveryinit() //First init DC name + + config := conf.GetConfig() var DBpoint string + var DC_NAME string var err error + DC_NAME = config.DCNAME - DBpoint = os.Getenv("DOCKER_DBPOINT") - if len(DBpoint) == 0 { - DBpoint, err = beego.AppConfig.String("DBPOINT") - if err != nil { - logs.Critical("DBPOINT URI error: %v", err) - panic(err) - } - + if len(DC_NAME) == 0 { + logs.Critical("DC_NAME URI error: %v", err) + panic(err) } + DBpoint = config.DBPOINT + + if len(DBpoint) == 0 { + logs.Critical("DBPOINT URI error: %v", err) + panic(err) + } + + + // if len(DBpoint) == 0 { + // DBpoint, err = beego.AppConfig.String("DBPOINT") + // if err != nil { + // logs.Critical("DBPOINT URI error: %v", err) + // panic(err) + // } + // } + + logs.Debug("connecting to datacenter db : " + DC_NAME + "-" + DBpoint) Mongoinit(DC_NAME + "-" + DBpoint) }