Modified the conf loading process, now with onion in conf/conf.go
This commit is contained in:
46
main.go
46
main.go
@@ -3,12 +3,18 @@ package main
|
||||
import (
|
||||
"os"
|
||||
|
||||
"cloud.o-forge.io/core/oc-catalog/conf"
|
||||
"cloud.o-forge.io/core/oc-catalog/routers"
|
||||
"cloud.o-forge.io/core/oc-catalog/services"
|
||||
|
||||
"github.com/beego/beego/logs"
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
"github.com/goraz/onion"
|
||||
)
|
||||
|
||||
const defaultConfigFile = "/etc/oc/catalog.json"
|
||||
const localConfigFile = "./local_catalog.json"
|
||||
|
||||
func main() {
|
||||
|
||||
// If we have any parameter, we run the beego directly
|
||||
@@ -16,16 +22,54 @@ func main() {
|
||||
beego.Run()
|
||||
}
|
||||
|
||||
loadConfig()
|
||||
|
||||
routers.Init()
|
||||
services.Init()
|
||||
|
||||
|
||||
if beego.BConfig.RunMode == "dev" {
|
||||
// beego.BConfig.WebConfig.DirectoryIndex = true
|
||||
beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
|
||||
}
|
||||
|
||||
beego.Run()
|
||||
|
||||
defer func() {
|
||||
services.MongoDisconnect()
|
||||
}()
|
||||
}
|
||||
|
||||
func loadConfig(){
|
||||
log := logs.NewLogger(10000)
|
||||
log.SetLogger("console")
|
||||
|
||||
configFile := ""
|
||||
var o *onion.Onion
|
||||
l3 := onion.NewEnvLayerPrefix("_", "OCCATALOG")
|
||||
l2, err := onion.NewFileLayer(defaultConfigFile, nil)
|
||||
if err == nil {
|
||||
logs.Info("Config file found : " + defaultConfigFile)
|
||||
configFile = defaultConfigFile
|
||||
}
|
||||
l1, err := onion.NewFileLayer(localConfigFile, nil)
|
||||
if err == nil {
|
||||
logs.Info("Local config file found " + localConfigFile + ", overriding default file")
|
||||
configFile = localConfigFile
|
||||
}
|
||||
if configFile == "" {
|
||||
logs.Info("No config file found, using env")
|
||||
o = onion.New(l3)
|
||||
} else if l1 == nil && l2 == nil {
|
||||
o = onion.New(l1, l2, l3)
|
||||
} else if l1 == nil {
|
||||
o = onion.New(l2, l3)
|
||||
} else if l2 == nil {
|
||||
o = onion.New(l1, l3)
|
||||
}
|
||||
|
||||
|
||||
conf.GetConfig().MongoURL = o.GetStringDefault("MongoURL", "mongodb://127.0.0.1:27017/beego-demo")
|
||||
conf.GetConfig().DCNAME = o.GetStringDefault("DCNAME", "DC_myDC")
|
||||
conf.GetConfig().DBPOINT = o.GetStringDefault("DBPOINT", "demdemo_06042021o")
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user