ini icon indicating copy to clipboard operation
ini copied to clipboard

MapTo() and ReflectFrom() does not handle incrementing key values

Open tomastzn opened this issue 4 years ago • 0 comments

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:

  1. Start with one .ini file containing values with - key names
  2. Load file and map it to structs
  3. Reflect the structs into empty ini.File
  4. Save it to a file and that should match the input file.

tomastzn avatar May 11 '20 02:05 tomastzn