ini
ini copied to clipboard
MapTo() and ReflectFrom() does not handle incrementing key values
Describe the bug
Values with incrementing names (written as - = something
in the file) are not mapped to structs or reflected from structs.
To Reproduce Starting with ini file like below:
something = 0
[Agents]
- = installRoot/agent_1.0.0
- = installRoot/agent_1.0.1
- = installRoot/agent_1.0.2
and structs like below:
type Agents struct {
InstalledAgents []string `ini:"-"`
}
type Config struct {
Something string `ini:"something"`
Agents `comment:"Installed agents directories"`
}
then loading the ini file with iniFile, _ := ini.Load(r)
where r is io.ReaderCloser
instance (actually just os.File), the instance of ini.File
will contain the keys with incrementing names #1, #2 and #3
however, in the following call:
c := &Config{}
iniFile.MapTo(c);
the c
will contain empty slice in InstalledAgents
.
Expected behavior
The values in INI file that end up in the ini.File
as Keys with incrementing key names #1
, #2
, etc. should be added to slice when the ini.File
is mapped to structs. Vice-versa, mapping/reflecting from structs should store values in ini file when written out.
Additional context Documentation on this part would be nice, perhaps an end-to-end example showing sequence like below would be great to explain it:
- Start with one .ini file containing values with
-
key names - Load file and map it to structs
- Reflect the structs into empty
ini.File
- Save it to a file and that should match the input file.