lib conf
This commit is contained in:
parent
29a75bced9
commit
85fc43368b
10
conf.go
10
conf.go
@ -10,9 +10,8 @@ import "sync"
|
||||
|
||||
type Config struct {
|
||||
MongoURL string
|
||||
DCNAME string
|
||||
DBPOINT string
|
||||
|
||||
DCNAME string
|
||||
DBPOINT string
|
||||
}
|
||||
|
||||
var instance *Config
|
||||
@ -24,3 +23,8 @@ func GetConfig() *Config {
|
||||
})
|
||||
return instance
|
||||
}
|
||||
|
||||
func SetConfig(config *Config) *Config {
|
||||
instance = config
|
||||
return instance
|
||||
}
|
||||
|
@ -30,7 +30,6 @@ func init() {
|
||||
// var baseConfig string
|
||||
var err error
|
||||
var conf map[string]string
|
||||
var MongoURL string
|
||||
var DBname string
|
||||
|
||||
ResourceMap = make(map[string]interface{})
|
||||
@ -43,23 +42,17 @@ func init() {
|
||||
}
|
||||
json.Unmarshal(db_conf, &conf)
|
||||
|
||||
if len(os.Getenv("DOCKER_ENVIRONMENT")) == 0 {
|
||||
MongoURL = conf["DB_URL_LOCAL"]
|
||||
} else {
|
||||
MongoURL = conf["DB_URL_DOCKER"]
|
||||
}
|
||||
DBname = lib.GetConfig().DCNAME + "-" + lib.GetConfig().DBPOINT
|
||||
|
||||
DBname = conf["DCNAME"] + "-" + conf["DBPOINT"]
|
||||
|
||||
lib.Logger.Info().Msg("Connecting to" + MongoURL)
|
||||
lib.Logger.Info().Msg("Connecting to" + lib.GetConfig().MongoURL)
|
||||
|
||||
MngoCtx, cancel = context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
createClient(MongoURL)
|
||||
createClient(lib.GetConfig().MongoURL)
|
||||
|
||||
lib.Logger.Info().Msg("Connecting mongo client to db " + DBname)
|
||||
prepareDB(conf["DCNAME"], conf["DBPOINT"])
|
||||
prepareDB(lib.GetConfig().DCNAME, lib.GetConfig().DBPOINT)
|
||||
|
||||
lib.Logger.Info().Msg("Database is READY")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user