Skip to content

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

Open
@tomastzn

Description

@tomastzn

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureCategorizes as related to a new feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions