struct: Support reflect from struct with non-anonymous structure pointer (#259)
Co-authored-by: ᴜɴᴋɴᴡᴏɴ <u@gogs.io>
Co-authored-by: ᴜɴᴋɴᴡᴏɴ <u@gogs.io>
yuangongji authored 3 years ago
GitHub committed 3 years ago
594 | 594 |
continue
|
595 | 595 |
}
|
596 | 596 |
|
597 | |
if (tpField.Type.Kind() == reflect.Ptr && tpField.Anonymous) ||
|
|
597 |
if (tpField.Type.Kind() == reflect.Ptr && tpField.Type.Elem().Kind() == reflect.Struct) ||
|
598 | 598 |
(tpField.Type.Kind() == reflect.Struct && tpField.Type.Name() != "Time") {
|
599 | 599 |
// Note: The only error here is section doesn't exist.
|
600 | 600 |
sec, err := s.f.GetSection(fieldName)
|
555 | 555 |
|
556 | 556 |
`)
|
557 | 557 |
})
|
|
558 |
|
|
559 |
Convey("Reflect from struct with non-anonymous structure pointer", func() {
|
|
560 |
cfg := ini.Empty()
|
|
561 |
type Rpc struct {
|
|
562 |
Enable bool `ini:"enable"`
|
|
563 |
Type string `ini:"type"`
|
|
564 |
Address string `ini:"addr"`
|
|
565 |
Name string `ini:"name"`
|
|
566 |
}
|
|
567 |
type Cfg struct {
|
|
568 |
Rpc *Rpc `ini:"rpc"`
|
|
569 |
}
|
|
570 |
|
|
571 |
config := &Cfg{
|
|
572 |
Rpc: &Rpc{
|
|
573 |
Enable: true,
|
|
574 |
Type: "type",
|
|
575 |
Address: "address",
|
|
576 |
Name: "name",
|
|
577 |
},
|
|
578 |
}
|
|
579 |
So(cfg.ReflectFrom(config), ShouldBeNil)
|
|
580 |
|
|
581 |
var buf bytes.Buffer
|
|
582 |
_, err = cfg.WriteTo(&buf)
|
|
583 |
So(buf.String(), ShouldEqual, `[rpc]
|
|
584 |
enable = true
|
|
585 |
type = type
|
|
586 |
addr = address
|
|
587 |
name = name
|
|
588 |
|
|
589 |
`)
|
|
590 |
})
|
558 | 591 |
})
|
559 | 592 |
}
|
560 | 593 |
|