Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,10 @@ func (s *Section) reflectFrom(val reflect.Value) error {
}

if r, ok := field.Interface().(StructReflector); ok {
return r.ReflectINIStruct(s.f)
if err := r.ReflectINIStruct(s.f); err != nil {
return err
}
continue
}

fieldName := s.parseFieldName(tpField.Name, rawName)
Expand Down
13 changes: 13 additions & 0 deletions struct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -871,12 +871,17 @@ func (es Employers) ReflectINIStruct(f *File) error {
return nil
}

type Address struct {
Line1, Line2 string
}

// 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{
Expand All @@ -889,6 +894,10 @@ func Test_StructReflector(t *testing.T) {
Title: "Consultant Engineer",
},
},
Address: Address{
Line1: "123 Ini Drive",
Line2: "Section 1",
},
}

f := Empty()
Expand All @@ -905,6 +914,10 @@ Title = Staff II Engineer

[Employer "EMC"]
Title = Consultant Engineer

[Address]
Line1 = 123 Ini Drive
Line2 = Section 1
`,
buf.String(),
)
Expand Down