2023-03-07 13:29:08 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-03-09 11:45:29 +01:00
|
|
|
"oc-discovery/models"
|
2023-03-07 13:29:08 +01:00
|
|
|
_ "oc-discovery/routers"
|
|
|
|
|
|
|
|
"github.com/beego/beego/logs"
|
|
|
|
beego "github.com/beego/beego/v2/server/web"
|
2023-03-09 11:45:29 +01:00
|
|
|
"github.com/goraz/onion"
|
2023-03-07 13:29:08 +01:00
|
|
|
)
|
|
|
|
|
2023-03-09 11:45:29 +01:00
|
|
|
const defaultConfigFile = "/etc/oc/discovery.json"
|
|
|
|
const localConfigFile = "./discovery.json"
|
|
|
|
|
2023-03-07 13:29:08 +01:00
|
|
|
func main() {
|
|
|
|
log := logs.NewLogger(10000)
|
|
|
|
log.SetLogger("console")
|
2023-03-09 11:45:29 +01:00
|
|
|
|
|
|
|
configFile := ""
|
|
|
|
var o *onion.Onion
|
|
|
|
l3 := onion.NewEnvLayerPrefix("_", "OCDISCOVERY_")
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
models.GetConfig().RedisUrl = o.GetStringDefault("redisurl", "localhost:6379")
|
|
|
|
models.GetConfig().RedisPassword = o.GetStringDefault("redispassword", "")
|
|
|
|
models.GetConfig().ZincUrl = o.GetStringDefault("zincurl", "http://localhost:4080")
|
|
|
|
models.GetConfig().ZincLogin = o.GetStringDefault("zinclogin", "admin")
|
|
|
|
models.GetConfig().ZincPassword = o.GetStringDefault("zincpassword", "admin")
|
2023-10-18 11:08:10 +02:00
|
|
|
models.GetConfig().IdentityFile = o.GetStringDefault("identityfile", "./identity.json")
|
2023-03-09 11:45:29 +01:00
|
|
|
models.GetConfig().Defaultpeers = o.GetStringDefault("defaultpeers", "./peers.json")
|
|
|
|
|
|
|
|
// Normal beego init
|
2023-10-18 15:24:57 +02:00
|
|
|
//if beego.BConfig.RunMode == "dev" {
|
|
|
|
beego.BConfig.WebConfig.DirectoryIndex = true
|
|
|
|
beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
|
|
|
|
//}
|
2023-03-07 13:29:08 +01:00
|
|
|
beego.Run()
|
|
|
|
}
|