You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If this were a major version change, I'd accept that "things change" but since it was a minor revision, I feel compelled to point out my now-broken use-case with this library. Maybe someone can correct my flaws and show me a valid way to do this. Or we can identify this as some sort of regression.
typetomlConfigstruct {
IncludeDirstringServices []*Config
}
typeConfigstruct {
NamestringPaths []string
}
funcloadConfigFile(configFilestring) (tomlConfig, error) {
varconfigtomlConfigifbuf, err:=ioutil.ReadFile(configFile); err!=nil {
returnconfig, err
} elseiferr:=toml.Unmarshal(buf, &config); err!=nil {
returnconfig, err
} elseifconfig.IncludeDir=="" {
returnconfig, nil
}
// include_dir is not empty, read in more config files from a conf.d folder.includedConfigFiles, err:=ioutil.ReadDir(config.IncludeDir)
iferr!=nil {
returnconfig, err
}
for_, includeFile:=rangeincludedConfigFiles {
filePath:=filepath.Join(config.IncludeDir, includeFile.Name())
if!strings.HasSuffix(filePath, ".conf") {
continue// Only read files that end with .conf.
} elseifbuf, err:=ioutil.ReadFile(filePath); err!=nil {
returnconfig, err
} elseiferr:=toml.Unmarshal(buf, &config); err!=nil {
returnconfig, err
}
}
returnconfig, nil
}
The above code works great with toml library 0.1.0. The Services slice is appended to for each [[services]] found in the included config files. In version 0.1.1 the slice only contains the data from the last config file Unmarshal()'d. Thoughts?
The text was updated successfully, but these errors were encountered:
I've worked around this by using a new tomlConfig for each loop iteration and appending the things I care about to the originally unmarshal'd dataset. I assume I was using a bug in the original code that was failing to clear out defaults. Providing a toml.UnmarshalAppend() function would be nifty so the above pattern can still be used. No priority from me here. Thanks!
Just checked and you're right: the behavior did change. I think the new behavior is more correct, but a config option could be added to disable 'clearing' of slices and maps. Are you up for implementing that?
If this were a major version change, I'd accept that "things change" but since it was a minor revision, I feel compelled to point out my now-broken use-case with this library. Maybe someone can correct my flaws and show me a valid way to do this. Or we can identify this as some sort of regression.
The above code works great with toml library 0.1.0. The
Services
slice is appended to for each[[services]]
found in the included config files. In version 0.1.1 the slice only contains the data from the last config fileUnmarshal()
'd. Thoughts?The text was updated successfully, but these errors were encountered: