Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow NonUniqueSections not working for Embedded Structs #327

Open
1 task done
olapiv opened this issue Sep 5, 2022 · 0 comments
Open
1 task done

Allow NonUniqueSections not working for Embedded Structs #327

olapiv opened this issue Sep 5, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@olapiv
Copy link

olapiv commented Sep 5, 2022

Version

v1.67.0

Describe the bug

When attempting to create an ini file from a struct containing a slice field, whereby

  1. the type of the slice contains an embedded struct
  2. the elements of the slice are supposed to be displayed as non-unique sections in the ini file

the elements of the slice are correctly shown as separate sections. However, the embedded struct is only shown once; the embedded struct of the last element is written to the first section.

To reproduce

type BaseSlot struct {
	Id int `ini:",nonunique"`
}

type BigSlot struct {
	*BaseSlot `ini:"big_slot,nonunique"`
	Color     string
}

type IniFile struct {
	BigSlots []BigSlot `ini:"big_slot,nonunique"`
}

func main() {
	iniFile := &IniFile{
		BigSlots: []BigSlot{
			{
				BaseSlot: &BaseSlot{
					Id: 3,
				},
				Color: "blue",
			},
			{
				BaseSlot: &BaseSlot{
					Id: 4,
				},
				Color: "red",
			},
		},
	}

	cfg := ini.Empty(ini.LoadOptions{
		AllowNonUniqueSections: true,
	})
	err := ini.ReflectFrom(cfg, iniFile)
	if err != nil {
		panic(err)
	}
	cfg.SaveTo("./some_file.ini")
}

the resulting file looks like this:

[big_slot]
Id    = 4
Color = blue

[big_slot]
Color = red

Expected behavior

The file to look as follows:

[big_slot]
Id    = 3
Color = blue

[big_slot]
Id    = 4
Color = red

Additional context

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@olapiv olapiv added the bug Something isn't working label Sep 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant