Compare commits

..

No commits in common. "aaaaaa" and "master" have entirely different histories.

View File

@ -1,7 +1,6 @@
package main
import (
"fmt"
"os"
"path/filepath"
"strings"
@ -17,8 +16,6 @@ import (
var cfgDir string
func init() {
etcPath := "/etc/itd.toml";
// Set up logger
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
@ -54,9 +51,15 @@ func init() {
// Set config defaults
setCfgDefaults()
// Load and watch config files
loadAndwatchCfgFile(etcPath)
loadAndwatchCfgFile(cfgPath)
// Load config files
etcProvider := file.Provider("/etc/itd.toml")
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
k.Load(env.Provider("ITD_", "_", func(s string) string {
@ -64,31 +67,17 @@ func init() {
}), nil)
}
func loadAndwatchCfgFile(filename string) {
provider := file.Provider(filename)
loadCfg(provider)
func cfgWatch(provider *file.File) {
// Watch for changes and reload when detected
provider.Watch(func(_ interface{}, err error) {
if err != nil {
return
}
loadCfg(provider)
k.Load(provider, toml.Parser())
})
}
func loadCfg(provider *file.File) {
fmt.Println("%#v\n", provider) // &file.File{path:"/etc/itd.toml"}
filename := ""
filename = provider.path // provider.path undefined (type *file.File has no field or method path)
filename = (*provider).path // (*provider).path undefined (type file.File has no field or method path)
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()))
}
}
func setCfgDefaults() {
k.Load(confmap.Provider(map[string]interface{}{
"bluetooth.adapter": "hci0",