conf singleton issue

This commit is contained in:
ycc 2024-09-04 14:21:01 +02:00
parent a0cbf9ac6f
commit ad96b50464
2 changed files with 9 additions and 4 deletions

View File

@ -37,7 +37,7 @@ func GetConfig() *Config {
} }
func SetConfig(mongoUrl string, database string, natsUrl string, lokiUrl string, logLevel string) *Config { func SetConfig(mongoUrl string, database string, natsUrl string, lokiUrl string, logLevel string) *Config {
once.Do(func() { /*once.Do(func() {
instance = &Config{ instance = &Config{
MongoUrl: mongoUrl, MongoUrl: mongoUrl,
MongoDatabase: database, MongoDatabase: database,
@ -45,6 +45,11 @@ func SetConfig(mongoUrl string, database string, natsUrl string, lokiUrl string,
LokiUrl: lokiUrl, LokiUrl: lokiUrl,
LogLevel: logLevel, LogLevel: logLevel,
} }
}) })*/
return instance GetConfig().MongoUrl = mongoUrl
GetConfig().MongoDatabase = database
GetConfig().NATSUrl = natsUrl
GetConfig().LokiUrl = lokiUrl
GetConfig().LogLevel = logLevel
return GetConfig()
} }

View File

@ -124,6 +124,7 @@ func GetLogger() zerolog.Logger {
* @return *Config * @return *Config
*/ */
func SetConfig(mongoUrl string, database string, natsUrl string, lokiUrl string, logLevel string) *config.Config { func SetConfig(mongoUrl string, database string, natsUrl string, lokiUrl string, logLevel string) *config.Config {
cfg := config.SetConfig(mongoUrl, database, natsUrl, lokiUrl, logLevel)
defer func() { defer func() {
if r := recover(); r != nil { if r := recover(); r != nil {
tools.UncatchedError = append(tools.UncatchedError, errors.New("Panic recovered in Init : "+fmt.Sprintf("%v", r)+" - "+string(debug.Stack()))) tools.UncatchedError = append(tools.UncatchedError, errors.New("Panic recovered in Init : "+fmt.Sprintf("%v", r)+" - "+string(debug.Stack())))
@ -131,7 +132,6 @@ func SetConfig(mongoUrl string, database string, natsUrl string, lokiUrl string,
} }
}() }()
logs.CreateLogger("main") logs.CreateLogger("main")
cfg := config.SetConfig(mongoUrl, database, natsUrl, lokiUrl, logLevel)
mongo.MONGOService.Init(models.GetModelsNames(), config.GetConfig()) // init the mongo service mongo.MONGOService.Init(models.GetModelsNames(), config.GetConfig()) // init the mongo service
/* /*
Here we will check if the resource model is already stored in the database Here we will check if the resource model is already stored in the database