File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -144,7 +144,9 @@ func customOptions(opt Options) Options {
144
144
opt .FuncMap = map [reflect.Type ]ParserFunc {}
145
145
}
146
146
for k , v := range defOpts .FuncMap {
147
- opt .FuncMap [k ] = v
147
+ if _ , exists := opt .FuncMap [k ]; ! exists {
148
+ opt .FuncMap [k ] = v
149
+ }
148
150
}
149
151
return opt
150
152
}
Original file line number Diff line number Diff line change @@ -1875,3 +1875,23 @@ func isNil(object interface{}) bool {
1875
1875
}
1876
1876
return false
1877
1877
}
1878
+
1879
+ func TestParseWithOptionsOverride (t * testing.T ) {
1880
+ type config struct {
1881
+ Interval time.Duration `env:"INTERVAL"`
1882
+ }
1883
+
1884
+ t .Setenv ("INTERVAL" , "1" )
1885
+
1886
+ var cfg config
1887
+
1888
+ isNoErr (t , ParseWithOptions (& cfg , Options {FuncMap : map [reflect.Type ]ParserFunc {
1889
+ reflect .TypeOf (time .Nanosecond ): func (value string ) (interface {}, error ) {
1890
+ intervalI , err := strconv .Atoi (value )
1891
+ if err != nil {
1892
+ return nil , err
1893
+ }
1894
+ return time .Duration (intervalI ), nil
1895
+ },
1896
+ }}))
1897
+ }
You can’t perform that action at this time.
0 commit comments