-
Notifications
You must be signed in to change notification settings - Fork 382
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Version
go1.24.2
Describe the bug
When a struct has a field implementing StructReflector, fields after that field are not processed.
To reproduce
Address is not present in the output.
type Address struct {
Line1, Line2 string
}
type Employer struct {
Name string
Title string
}
type Employers []*Employer
func (es Employers) ReflectINIStruct(f *File) error {
for _, e := range es {
f.Section(e.Name).Key("Title").SetValue(e.Title)
}
return nil
}
// Inspired by https://github.com/go-ini/ini/issues/199
func Test_StructReflector(t *testing.T) {
t.Run("reflect with StructReflector interface", func(t *testing.T) {
p := &struct {
FirstName string
Employer Employers
Address Address
}{
FirstName: "Andrew",
Employer: []*Employer{
{
Name: `Employer "VMware"`,
Title: "Staff II Engineer",
},
{
Name: `Employer "EMC"`,
Title: "Consultant Engineer",
},
},
Address: Address{
Line1: "123 Ini Drive",
Line2: "Section 1",
},
}
f := Empty()
assert.NoError(t, f.ReflectFrom(p))
var buf bytes.Buffer
_, err := f.WriteTo(&buf)
require.NoError(t, err)
assert.Equal(t, `FirstName = Andrew
[Employer "VMware"]
Title = Staff II Engineer
[Employer "EMC"]
Title = Consultant Engineer
[Address]
Line1 = 123 Ini Drive
Line2 = Section 1
`,
buf.String(),
)
})
}
Expected behavior
Address should be present in the output.
Additional context
No response
Code of Conduct
- I agree to follow this project's Code of Conduct
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working