Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit 18f04e6

Browse files
committed
Default MatchName in NewDecoder
1 parent 14df28d commit 18f04e6

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

mapstructure.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,10 @@ func NewDecoder(config *DecoderConfig) (*Decoder, error) {
381381
config.TagName = "mapstructure"
382382
}
383383

384+
if config.MatchName == nil {
385+
config.MatchName = strings.EqualFold
386+
}
387+
384388
result := &Decoder{
385389
config: config,
386390
}
@@ -1345,7 +1349,7 @@ func (d *Decoder) decodeStructFromMap(name string, dataVal, val reflect.Value) e
13451349
continue
13461350
}
13471351

1348-
if d.matchName(mK, fieldName) {
1352+
if d.config.MatchName(mK, fieldName) {
13491353
rawMapKey = dataValKey
13501354
rawMapVal = dataVal.MapIndex(dataValKey)
13511355
break
@@ -1433,14 +1437,6 @@ func (d *Decoder) decodeStructFromMap(name string, dataVal, val reflect.Value) e
14331437
return nil
14341438
}
14351439

1436-
func (d *Decoder) matchName(mapKey, fieldName string) bool {
1437-
if d.config.MatchName != nil {
1438-
return d.config.MatchName(mapKey, fieldName)
1439-
}
1440-
1441-
return strings.EqualFold(mapKey, fieldName)
1442-
}
1443-
14441440
func isEmptyValue(v reflect.Value) bool {
14451441
switch getKind(v) {
14461442
case reflect.Array, reflect.Map, reflect.Slice, reflect.String:

0 commit comments

Comments
 (0)