deprecated-oc-catalog/main.go

81 lines
1.8 KiB
Go
Raw Normal View History

2023-03-03 14:43:11 +01:00
package main
import (
"os"
2024-07-29 18:02:29 +02:00
"cloud.o-forge.io/core/deprecated-oc-catalog/conf"
"cloud.o-forge.io/core/deprecated-oc-catalog/routers"
"cloud.o-forge.io/core/deprecated-oc-catalog/services"
2023-03-03 14:43:11 +01:00
"github.com/beego/beego/logs"
2023-03-03 14:43:11 +01:00
beego "github.com/beego/beego/v2/server/web"
"github.com/goraz/onion"
2023-03-03 14:43:11 +01:00
)
const defaultConfigFile = "/etc/oc/catalog.json"
const localConfigFile = "./local_catalog.json"
2023-03-03 14:43:11 +01:00
func main() {
// If we have any parameter, we run the beego directly
if len(os.Args) > 1 {
beego.Run()
}
loadConfig()
2023-03-03 14:43:11 +01:00
routers.Init()
services.Init()
2023-12-04 14:46:36 +01:00
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"
2023-12-04 14:46:36 +01:00
// }
2023-03-03 14:43:11 +01:00
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)
}
2023-12-04 14:46:36 +01:00
conf.GetConfig().MongoURL = o.GetStringDefault("MongoURL", "mongodb://127.0.0.1:27017")
conf.GetConfig().DCNAME = o.GetStringDefault("DCNAME", "DC_myDC")
2024-02-15 10:52:29 +01:00
conf.GetConfig().DBPOINT = o.GetStringDefault("DBPOINT", "demo_06042021")
}