Compare commits

..

No commits in common. "a254762288317377c5f041c35a6ea5f9d76f034e" and "248beffa2f29741093feee220c6d745cb3bfab3a" have entirely different histories.

View File

@ -1,7 +1,6 @@
package main package main
import ( import (
"fmt"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -17,8 +16,6 @@ import (
var cfgDir string var cfgDir string
func init() { func init() {
etcPath := "/etc/itd.toml";
// Set up logger // Set up logger
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr}) log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
@ -54,9 +51,15 @@ func init() {
// Set config defaults // Set config defaults
setCfgDefaults() setCfgDefaults()
// Load and watch config files // Load config files
loadAndwatchCfgFile(etcPath) etcProvider := file.Provider("/etc/itd.toml")
loadAndwatchCfgFile(cfgPath) cfgProvider := file.Provider(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 {
@ -64,22 +67,14 @@ func init() {
}), nil) }), nil)
} }
func loadAndwatchCfgFile(filename string) { func cfgWatch(provider *file.File) {
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()))
}
// 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
} }
if cfgError := k.Load(provider, toml.Parser()); cfgError != nil { k.Load(provider, toml.Parser())
log.Warn().Msg(fmt.Sprintf("Error while trying to read %s: %s\n", filename, cfgError.Error()))
}
}) })
} }