WIP: Attempting to move code duplication into another function

What is this language's problem?
This commit is contained in:
Hunman 2022-12-30 01:35:45 +01:00
parent a254762288
commit 5a84bf8148
1 changed files with 12 additions and 6 deletions

View File

@ -67,9 +67,7 @@ func init() {
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()))
}
loadCfg(provider)
// Watch for changes and reload when detected
provider.Watch(func(_ interface{}, err error) {
@ -77,10 +75,18 @@ func loadAndwatchCfgFile(filename string) {
return
}
loadCfg(provider)
})
}
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() {