Skip to content

Commit

Permalink
Merge pull request #19 from DrOctavius/main
Browse files Browse the repository at this point in the history
Added config env reader
  • Loading branch information
DrOctavius authored Sep 9, 2022
2 parents 994613f + 26fce24 commit df05ec5
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions core/config/autoloader/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,14 @@ func StartAutoLoader(c Config) error {

//

// We should save the configuration only if has being changed!
// But this can be made by saving in other temporary location, and after that comparing the contents of the both files!

// Save again the config with the newly added/removed keys based on the app structure!
if _err := SaveConfigFromMemory(c); _err != nil {
return err.New(0, "failed to save config from memory -> "+_err.Error())
}

// ===================== ENV ========================\\
if _err = env.Parse(&cfgData.MainConfig); _err != nil {
return err.New(0, "failed to set env variables for MainConfig -> "+_err.Error())
Expand All @@ -259,16 +267,6 @@ func StartAutoLoader(c Config) error {
}
// ===================== ENV ========================\\

//

// We should save the configuration only if has being changed!
// But this can be made by saving in other temporary location, and after that comparing the contents of the both files!

// Save again the config with the newly added/removed keys based on the app structure!
if _err := SaveConfigFromMemory(c); _err != nil {
return err.New(0, "failed to save config from memory -> "+_err.Error())
}

// Launch config watcher... if something changes, we will notify the others
cfgData.MainConfigViper.WatchConfig()
cfgData.MainConfigViper.OnConfigChange(func(e fsnotify.Event) {
Expand All @@ -289,6 +287,18 @@ func StartAutoLoader(c Config) error {
// return false
}

// ===================== ENV ========================\\
if _err = env.Parse(&cfgData.MainConfig); _err != nil {
log.Println(_err)
//return err.New(0, "failed to set env variables for MainConfig -> "+_err.Error())
}

if _err = env.Parse(c.CustomConfig); _err != nil {
log.Println(_err)
//return err.New(0, "failed to set env variables for CustomConfig -> "+_err.Error())
}
// ===================== ENV ========================\\

// log.Println(cfgData.MainConfig)

// TODO: we can create other triggers from here...
Expand Down

0 comments on commit df05ec5

Please sign in to comment.