49 lines
927 B
Go
49 lines
927 B
Go
package conf
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"github.com/beego/beego/logs"
|
|
"github.com/goraz/onion"
|
|
)
|
|
|
|
type Config struct {
|
|
MonitorPath string
|
|
MongoUrl string
|
|
DBName string
|
|
Logs string
|
|
LokiUrl string
|
|
NatsUrl string
|
|
}
|
|
|
|
var instance *Config
|
|
var once sync.Once
|
|
|
|
const defaultConfigFile = "/etc/oc/schedulerd.json"
|
|
|
|
func init() {
|
|
configFile := ""
|
|
var o *onion.Onion
|
|
|
|
l3 := onion.NewEnvLayerPrefix("_", "OCSCHEDULERD_")
|
|
l2, err := onion.NewFileLayer(defaultConfigFile, nil)
|
|
if err == nil {
|
|
logs.Info("Config file found : " + defaultConfigFile)
|
|
configFile = defaultConfigFile
|
|
}
|
|
if configFile == "" || l2 == nil {
|
|
logs.Info("No config file found, using env")
|
|
o = onion.New(l3)
|
|
} else {
|
|
o = onion.New(l2, l3)
|
|
}
|
|
GetConfig().MonitorPath = o.GetStringDefault("MONITORD_PATH", "../oc-monitord/oc-monitord")
|
|
}
|
|
|
|
func GetConfig() *Config {
|
|
once.Do(func() {
|
|
instance = &Config{}
|
|
})
|
|
return instance
|
|
}
|