WIP: Attempting to move code duplication into another function
What is this language's problem?
This commit is contained in:
parent
a254762288
commit
5a84bf8148
18
config.go
18
config.go
@ -67,9 +67,7 @@ func init() {
|
|||||||
func loadAndwatchCfgFile(filename string) {
|
func loadAndwatchCfgFile(filename string) {
|
||||||
provider := file.Provider(filename)
|
provider := file.Provider(filename)
|
||||||
|
|
||||||
if cfgError := k.Load(provider, toml.Parser()); cfgError != nil {
|
loadCfg(provider)
|
||||||
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) {
|
||||||
@ -77,12 +75,20 @@ func loadAndwatchCfgFile(filename string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfgError := k.Load(provider, toml.Parser()); cfgError != nil {
|
loadCfg(provider)
|
||||||
log.Warn().Msg(fmt.Sprintf("Error while trying to read %s: %s\n", filename, cfgError.Error()))
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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() {
|
func setCfgDefaults() {
|
||||||
k.Load(confmap.Provider(map[string]interface{}{
|
k.Load(confmap.Provider(map[string]interface{}{
|
||||||
"bluetooth.adapter": "hci0",
|
"bluetooth.adapter": "hci0",
|
||||||
|
Loading…
Reference in New Issue
Block a user