File tree 2 files changed +34
-1
lines changed
2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -595,7 +595,7 @@ func (s *Section) reflectFrom(val reflect.Value) error {
595
595
continue
596
596
}
597
597
598
- if (tpField .Type .Kind () == reflect .Ptr && tpField .Anonymous ) ||
598
+ if (tpField .Type .Kind () == reflect .Ptr && tpField .Type . Elem (). Kind () == reflect . Struct ) ||
599
599
(tpField .Type .Kind () == reflect .Struct && tpField .Type .Name () != "Time" ) {
600
600
// Note: The only error here is section doesn't exist.
601
601
sec , err := s .f .GetSection (fieldName )
Original file line number Diff line number Diff line change @@ -554,6 +554,39 @@ None =
554
554
last_name = Doe
555
555
omitempty = 9
556
556
557
+ ` )
558
+ })
559
+
560
+ Convey ("Reflect from struct with non-anonymous structure pointer" , func () {
561
+ cfg := ini .Empty ()
562
+ type Rpc struct {
563
+ Enable bool `ini:"enable"`
564
+ Type string `ini:"type"`
565
+ Address string `ini:"addr"`
566
+ Name string `ini:"name"`
567
+ }
568
+ type Cfg struct {
569
+ Rpc * Rpc `ini:"rpc"`
570
+ }
571
+
572
+ config := & Cfg {
573
+ Rpc : & Rpc {
574
+ Enable : true ,
575
+ Type : "type" ,
576
+ Address : "address" ,
577
+ Name : "name" ,
578
+ },
579
+ }
580
+ So (cfg .ReflectFrom (config ), ShouldBeNil )
581
+
582
+ var buf bytes.Buffer
583
+ _ , err = cfg .WriteTo (& buf )
584
+ So (buf .String (), ShouldEqual , `[rpc]
585
+ enable = true
586
+ type = type
587
+ addr = address
588
+ name = name
589
+
557
590
` )
558
591
})
559
592
})
You can’t perform that action at this time.
0 commit comments