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

Commit

Permalink
Default MatchName in NewDecoder
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Sep 14, 2021
1 parent 14df28d commit 18f04e6
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions mapstructure.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,10 @@ func NewDecoder(config *DecoderConfig) (*Decoder, error) {
config.TagName = "mapstructure"
}

if config.MatchName == nil {
config.MatchName = strings.EqualFold
}

result := &Decoder{
config: config,
}
Expand Down Expand Up @@ -1345,7 +1349,7 @@ func (d *Decoder) decodeStructFromMap(name string, dataVal, val reflect.Value) e
continue
}

if d.matchName(mK, fieldName) {
if d.config.MatchName(mK, fieldName) {
rawMapKey = dataValKey
rawMapVal = dataVal.MapIndex(dataValKey)
break
Expand Down Expand Up @@ -1433,14 +1437,6 @@ func (d *Decoder) decodeStructFromMap(name string, dataVal, val reflect.Value) e
return nil
}

func (d *Decoder) matchName(mapKey, fieldName string) bool {
if d.config.MatchName != nil {
return d.config.MatchName(mapKey, fieldName)
}

return strings.EqualFold(mapKey, fieldName)
}

func isEmptyValue(v reflect.Value) bool {
switch getKind(v) {
case reflect.Array, reflect.Map, reflect.Slice, reflect.String:
Expand Down

0 comments on commit 18f04e6

Please sign in to comment.