Codebase list golang-github-go-ini-ini / abeaefd
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
2 changed file(s) with 34 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
594594 continue
595595 }
596596
597 if (tpField.Type.Kind() == reflect.Ptr && tpField.Anonymous) ||
597 if (tpField.Type.Kind() == reflect.Ptr && tpField.Type.Elem().Kind() == reflect.Struct) ||
598598 (tpField.Type.Kind() == reflect.Struct && tpField.Type.Name() != "Time") {
599599 // Note: The only error here is section doesn't exist.
600600 sec, err := s.f.GetSection(fieldName)
555555
556556 `)
557557 })
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 })
558591 })
559592 }
560593