@@ -539,14 +539,25 @@ None =
539
539
cfg := ini .Empty ()
540
540
type SpecialStruct struct {
541
541
FirstName string `ini:"first_name"`
542
- LastName string `ini:"last_name"`
542
+ LastName string `ini:"last_name,omitempty "`
543
543
JustOmitMe string `ini:"omitempty"`
544
544
LastLogin time.Time `ini:"last_login,omitempty"`
545
545
LastLogin2 time.Time `ini:",omitempty"`
546
546
NotEmpty int `ini:"omitempty"`
547
+ Number int64 `ini:",omitempty"`
548
+ Ages uint `ini:",omitempty"`
549
+ Population uint64 `ini:",omitempty"`
550
+ Coordinate float64 `ini:",omitempty"`
551
+ Flag bool `ini:",omitempty"`
552
+ Note * string `ini:",omitempty"`
553
+ }
554
+ special := & SpecialStruct {
555
+ FirstName : "John" ,
556
+ LastName : "Doe" ,
557
+ NotEmpty : 9 ,
547
558
}
548
559
549
- So (ini .ReflectFrom (cfg , & SpecialStruct { FirstName : "John" , LastName : "Doe" , NotEmpty : 9 } ), ShouldBeNil )
560
+ So (ini .ReflectFrom (cfg , special ), ShouldBeNil )
550
561
551
562
var buf bytes.Buffer
552
563
_ , err = cfg .WriteTo (& buf )
@@ -724,12 +735,36 @@ path = /tmp/gpm-profiles/test1.profile
724
735
AllowShadows : true ,
725
736
})
726
737
type ShadowStruct struct {
727
- StringArray []string `ini:"sa,,allowshadow"`
728
- EmptyStringArrat []string `ini:"empty,omitempty,allowshadow"`
729
- Allowshadow []string `ini:"allowshadow,,allowshadow"`
738
+ StringArray []string `ini:"sa,,allowshadow"`
739
+ EmptyStringArrat []string `ini:"empty,omitempty,allowshadow"`
740
+ Allowshadow []string `ini:"allowshadow,,allowshadow"`
741
+ Dates []time.Time `ini:",,allowshadow"`
742
+ Places []string `ini:",,allowshadow"`
743
+ Years []int `ini:",,allowshadow"`
744
+ Numbers []int64 `ini:",,allowshadow"`
745
+ Ages []uint `ini:",,allowshadow"`
746
+ Populations []uint64 `ini:",,allowshadow"`
747
+ Coordinates []float64 `ini:",,allowshadow"`
748
+ Flags []bool `ini:",,allowshadow"`
749
+ None []int `ini:",,allowshadow"`
750
+ }
751
+
752
+ shadow := & ShadowStruct {
753
+ StringArray : []string {"s1" , "s2" },
754
+ Allowshadow : []string {"s3" , "s4" },
755
+ Dates : []time.Time {time .Date (2020 , 9 , 12 , 00 , 00 , 00 , 651387237 , time .UTC ),
756
+ time .Date (2020 , 9 , 12 , 00 , 00 , 00 , 651387237 , time .UTC )},
757
+ Places : []string {"HangZhou" , "Boston" },
758
+ Years : []int {1993 , 1994 },
759
+ Numbers : []int64 {10010 , 10086 },
760
+ Ages : []uint {18 , 19 },
761
+ Populations : []uint64 {12345678 , 98765432 },
762
+ Coordinates : []float64 {192.168 , 10.11 },
763
+ Flags : []bool {true , false },
764
+ None : []int {},
730
765
}
731
766
732
- So (ini .ReflectFrom (cfg , & ShadowStruct { StringArray : [] string { "s1" , "s2" }, Allowshadow : [] string { "s3" , "s4" }} ), ShouldBeNil )
767
+ So (ini .ReflectFrom (cfg , shadow ), ShouldBeNil )
733
768
734
769
var buf bytes.Buffer
735
770
_ , err := cfg .WriteTo (& buf )
@@ -738,6 +773,22 @@ path = /tmp/gpm-profiles/test1.profile
738
773
sa = s2
739
774
allowshadow = s3
740
775
allowshadow = s4
776
+ Dates = 2020-09-12T00:00:00Z
777
+ Places = HangZhou
778
+ Places = Boston
779
+ Years = 1993
780
+ Years = 1994
781
+ Numbers = 10010
782
+ Numbers = 10086
783
+ Ages = 18
784
+ Ages = 19
785
+ Populations = 12345678
786
+ Populations = 98765432
787
+ Coordinates = 192.168
788
+ Coordinates = 10.11
789
+ Flags = true
790
+ Flags = false
791
+ None =
741
792
742
793
` )
743
794
})
0 commit comments