Warn when Koanf read fails #47
25
config.go
25
config.go
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@ -53,15 +54,9 @@ func init() {
|
|||||||
// Set config defaults
|
// Set config defaults
|
||||||
setCfgDefaults()
|
setCfgDefaults()
|
||||||
|
|
||||||
// Load config files
|
// Load and watch config files
|
||||||
etcProvider := file.Provider(etcPath)
|
loadAndwatchCfgFile(etcPath)
|
||||||
cfgProvider := file.Provider(cfgPath)
|
loadAndwatchCfgFile(cfgPath)
|
||||||
k.Load(etcProvider, toml.Parser())
|
|
||||||
k.Load(cfgProvider, toml.Parser())
|
|
||||||
|
|
||||||
// Watch configs for changes
|
|
||||||
cfgWatch(etcProvider)
|
|
||||||
cfgWatch(cfgProvider)
|
|
||||||
|
|
||||||
// Load envireonment variables
|
// Load envireonment variables
|
||||||
k.Load(env.Provider("ITD_", "_", func(s string) string {
|
k.Load(env.Provider("ITD_", "_", func(s string) string {
|
||||||
@ -69,14 +64,22 @@ func init() {
|
|||||||
}), nil)
|
}), nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func cfgWatch(provider *file.File) {
|
func loadAndwatchCfgFile(filename string) {
|
||||||
|
provider := file.Provider(filename)
|
||||||
|
|
||||||
|
if cfgError := k.Load(provider, toml.Parser()); cfgError != nil {
|
||||||
|
log.Warn().Msg(fmt.Sprintf("Error while trying to read %s: %s\n", filename, cfgError.Error()))
|
||||||
Hunman marked this conversation as resolved
Elara6331
commented
Review
```diff
- log.Warn().Msg(fmt.Sprintf("Error while trying to read %s: %s\n", filename, cfgError.Error()))
+ log.Warn().Str("filename", filename).Err(cfgError).Msg("Error while trying to read config file")
```
|
|||||||
|
}
|
||||||
|
|
||||||
// Watch for changes and reload when detected
|
// Watch for changes and reload when detected
|
||||||
provider.Watch(func(_ interface{}, err error) {
|
provider.Watch(func(_ interface{}, err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
k.Load(provider, toml.Parser())
|
if cfgError := k.Load(provider, toml.Parser()); cfgError != nil {
|
||||||
|
log.Warn().Msg(fmt.Sprintf("Error while trying to read %s: %s\n", filename, cfgError.Error()))
|
||||||
Hunman marked this conversation as resolved
Elara6331
commented
Same as above
Same as above
```diff
- log.Warn().Msg(fmt.Sprintf("Error while trying to read %s: %s\n", filename, cfgError.Error()))
+ log.Warn().Str("filename", filename).Err(cfgError).Msg("Error while trying to read config file")
```
|
|||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user