oc-schedulerd/conf/conf.go

65 lines
1.5 KiB
Go
Raw Normal View History

2024-07-03 10:21:17 +02:00
package conf
import (
"sync"
"github.com/beego/beego/logs"
"github.com/goraz/onion"
)
type Config struct {
OcCatalogUrl string
2024-08-09 18:44:33 +02:00
MongoUrl string
2024-07-03 10:21:17 +02:00
Logs string
2024-07-29 15:45:32 +02:00
LokiUrl string
2024-08-09 18:44:33 +02:00
NatsUrl string
2024-07-03 10:21:17 +02:00
}
var instance *Config
var once sync.Once
2024-07-03 10:22:22 +02:00
const defaultConfigFile = "/etc/oc/scheduler.json"
2024-07-03 10:21:17 +02:00
const localConfigFile = "./conf/local_scheduler.json"
func init(){
configFile := ""
var o *onion.Onion
l3 := onion.NewEnvLayerPrefix("_", "OCSCHEDULER_")
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)
}
GetConfig().OcCatalogUrl = o.GetStringDefault("oc-catalog", "https://localhost:49618")
GetConfig().Logs = o.GetStringDefault("loglevel", "info")
2024-07-29 15:45:32 +02:00
GetConfig().LokiUrl = o.GetStringDefault("loki_url","http://127.0.0.1:3100")
2024-08-09 18:44:33 +02:00
GetConfig().LokiUrl = o.GetStringDefault("nats_url","http://127.0.0.1:4222")
GetConfig().MongoUrl = o.GetStringDefault("mongo_url","mongodb://127.0.0.1:27017")
2024-07-03 10:21:17 +02:00
}
func GetConfig() *Config {
once.Do(func() {
instance = &Config{}
})
return instance
}