diff options
author | Martin Kraft <martinkraft@gmail.com> | 2018-05-22 12:54:00 -0400 |
---|---|---|
committer | Martin Kraft <martinkraft@gmail.com> | 2018-05-22 12:54:00 -0400 |
commit | 4c683aff7627040ff811f065848a820b2cb19d59 (patch) | |
tree | 668061e8acfd8827fd02bab18a998b7986944296 /vendor/github.com/mitchellh/mapstructure | |
parent | eb78d273f39202046fa71555a5a19b0ec8a95cb3 (diff) | |
parent | 1af1bce6199597bb2d41ddcdc00ef0f28a73c83e (diff) | |
download | chat-4c683aff7627040ff811f065848a820b2cb19d59.tar.gz chat-4c683aff7627040ff811f065848a820b2cb19d59.tar.bz2 chat-4c683aff7627040ff811f065848a820b2cb19d59.zip |
Merge remote-tracking branch 'origin/master' into advanced-permissions-phase-2
Diffstat (limited to 'vendor/github.com/mitchellh/mapstructure')
-rw-r--r-- | vendor/github.com/mitchellh/mapstructure/mapstructure.go | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/vendor/github.com/mitchellh/mapstructure/mapstructure.go b/vendor/github.com/mitchellh/mapstructure/mapstructure.go index aaf12a295..13cc5e3d6 100644 --- a/vendor/github.com/mitchellh/mapstructure/mapstructure.go +++ b/vendor/github.com/mitchellh/mapstructure/mapstructure.go @@ -644,16 +644,28 @@ func (d *Decoder) decodeMapFromStruct(name string, dataVal reflect.Value, val re return fmt.Errorf("cannot assign type '%s' to map value field of type '%s'", v.Type(), valMap.Type().Elem()) } + tagValue := f.Tag.Get(d.config.TagName) + tagParts := strings.Split(tagValue, ",") + // Determine the name of the key in the map keyName := f.Name - tagValue := f.Tag.Get(d.config.TagName) - tagValue = strings.SplitN(tagValue, ",", 2)[0] - if tagValue != "" { - if tagValue == "-" { + if tagParts[0] != "" { + if tagParts[0] == "-" { continue } + keyName = tagParts[0] + } - keyName = tagValue + // If "squash" is specified in the tag, we squash the field down. + squash := false + for _, tag := range tagParts[1:] { + if tag == "squash" { + squash = true + break + } + } + if squash && v.Kind() != reflect.Struct { + return fmt.Errorf("cannot squash non-struct type '%s'", v.Type()) } switch v.Kind() { @@ -673,7 +685,13 @@ func (d *Decoder) decodeMapFromStruct(name string, dataVal reflect.Value, val re return err } - valMap.SetMapIndex(reflect.ValueOf(keyName), vMap) + if squash { + for _, k := range vMap.MapKeys() { + valMap.SetMapIndex(k, vMap.MapIndex(k)) + } + } else { + valMap.SetMapIndex(reflect.ValueOf(keyName), vMap) + } default: valMap.SetMapIndex(reflect.ValueOf(keyName), v) |