diff --git a/overrides_test.go b/overrides_test.go index dd2aa9b..ed59e70 100644 --- a/overrides_test.go +++ b/overrides_test.go @@ -155,11 +155,11 @@ func deepCheckValue(assert *assert.Assertions, v *Viper, l layer, keys []string, } // deep scan of the map to get the final value - switch val.(type) { + switch v := val.(type) { case map[interface{}]interface{}: m = cast.ToStringMap(val) case map[string]interface{}: - m = val.(map[string]interface{}) + m = v default: assert.Fail(fmt.Sprintf("%s is not a map[string]interface{}", ms)) return diff --git a/util.go b/util.go index 952cad4..178f112 100644 --- a/util.go +++ b/util.go @@ -68,14 +68,14 @@ func copyAndInsensitiviseMap(m map[string]interface{}) map[string]interface{} { func insensitiviseMap(m map[string]interface{}) { for key, val := range m { - switch val.(type) { + switch v := val.(type) { case map[interface{}]interface{}: // nested map: cast and recursively insensitivise val = cast.ToStringMap(val) insensitiviseMap(val.(map[string]interface{})) case map[string]interface{}: // nested map: recursively insensitivise - insensitiviseMap(val.(map[string]interface{})) + insensitiviseMap(v) } lower := strings.ToLower(key) diff --git a/viper.go b/viper.go index a32ab73..b82a788 100644 --- a/viper.go +++ b/viper.go @@ -491,13 +491,13 @@ func (v *Viper) searchMap(source map[string]interface{}, path []string) interfac } // Nested case - switch next.(type) { + switch n := next.(type) { case map[interface{}]interface{}: return v.searchMap(cast.ToStringMap(next), path[1:]) case map[string]interface{}: // Type assertion is safe here since it is only reached // if the type of `next` is the same as the type being asserted - return v.searchMap(next.(map[string]interface{}), path[1:]) + return v.searchMap(n, path[1:]) default: // got a value but nested key expected, return "nil" for not found return nil @@ -535,13 +535,13 @@ func (v *Viper) searchMapWithPathPrefixes(source map[string]interface{}, path [] // Nested case var val interface{} - switch next.(type) { + switch n := next.(type) { case map[interface{}]interface{}: val = v.searchMapWithPathPrefixes(cast.ToStringMap(next), path[i:]) case map[string]interface{}: // Type assertion is safe here since it is only reached // if the type of `next` is the same as the type being asserted - val = v.searchMapWithPathPrefixes(next.(map[string]interface{}), path[i:]) + val = v.searchMapWithPathPrefixes(n, path[i:]) default: // got a value but nested key expected, do nothing and look for next prefix } @@ -1675,9 +1675,9 @@ func (v *Viper) flattenAndMergeMap(shadow map[string]bool, m map[string]interfac } for k, val := range m { fullKey := prefix + k - switch val.(type) { + switch v := val.(type) { case map[string]interface{}: - m2 = val.(map[string]interface{}) + m2 = v case map[interface{}]interface{}: m2 = cast.ToStringMap(val) default: