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
2 changes: 1 addition & 1 deletion struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ func (s *Section) reflectFrom(val reflect.Value) error {
continue
}

if (tpField.Type.Kind() == reflect.Ptr && tpField.Anonymous) ||
if (tpField.Type.Kind() == reflect.Ptr && tpField.Type.Elem().Kind() == reflect.Struct) ||
(tpField.Type.Kind() == reflect.Struct && tpField.Type.Name() != "Time") {
// Note: The only error here is section doesn't exist.
sec, err := s.f.GetSection(fieldName)
Expand Down
33 changes: 33 additions & 0 deletions struct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,39 @@ None =
last_name = Doe
omitempty = 9

`)
})

Convey("Reflect from struct with non-anonymous structure pointer", func() {
cfg := ini.Empty()
type Rpc struct {
Enable bool `ini:"enable"`
Type string `ini:"type"`
Address string `ini:"addr"`
Name string `ini:"name"`
}
type Cfg struct {
Rpc *Rpc `ini:"rpc"`
}

config := &Cfg{
Rpc: &Rpc{
Enable: true,
Type: "type",
Address: "address",
Name: "name",
},
}
So(cfg.ReflectFrom(config), ShouldBeNil)

var buf bytes.Buffer
_, err = cfg.WriteTo(&buf)
So(buf.String(), ShouldEqual, `[rpc]
enable = true
type = type
addr = address
name = name

`)
})
})
Expand Down