oc-workflow/main.go

54 lines
1.4 KiB
Go
Raw Normal View History

2024-07-11 11:40:11 +02:00
package main
import (
2024-07-11 15:40:34 +02:00
"oc-workflow/conf"
2024-07-11 11:40:11 +02:00
_ "oc-workflow/routers"
"github.com/beego/beego/logs"
beego "github.com/beego/beego/v2/server/web"
"github.com/goraz/onion"
)
const defaultConfigFile = "/etc/oc/workflow.json"
const localConfigFile = "./workflow.json"
func main() {
log := logs.NewLogger(10000)
log.SetLogger("console")
configFile := ""
var o *onion.Onion
l3 := onion.NewEnvLayerPrefix("_", "OCWORKFLOW_")
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)
}
2024-07-11 15:40:34 +02:00
conf.GetConfig().MongoUrl = o.GetStringDefault("mongourl", "http://localhost:4080")
conf.GetConfig().MongoLogin = o.GetStringDefault("mongologin", "admin")
conf.GetConfig().MongoPassword = o.GetStringDefault("mongopassword", "admin")
2024-07-11 11:40:11 +02:00
// Normal beego init
//if beego.BConfig.RunMode == "dev" {
beego.BConfig.WebConfig.DirectoryIndex = true
beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
//}
beego.Run()
}