fixed typeSwitchVar warnings

This commit is contained in:
Veselkov Konstantin 2018-09-30 23:26:14 +04:00
parent 62edee3196
commit f5346596bf
3 changed files with 10 additions and 10 deletions

View file

@ -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 // deep scan of the map to get the final value
switch val.(type) { switch v := val.(type) {
case map[interface{}]interface{}: case map[interface{}]interface{}:
m = cast.ToStringMap(val) m = cast.ToStringMap(val)
case map[string]interface{}: case map[string]interface{}:
m = val.(map[string]interface{}) m = v
default: default:
assert.Fail(fmt.Sprintf("%s is not a map[string]interface{}", ms)) assert.Fail(fmt.Sprintf("%s is not a map[string]interface{}", ms))
return return

View file

@ -68,14 +68,14 @@ func copyAndInsensitiviseMap(m map[string]interface{}) map[string]interface{} {
func insensitiviseMap(m map[string]interface{}) { func insensitiviseMap(m map[string]interface{}) {
for key, val := range m { for key, val := range m {
switch val.(type) { switch v := val.(type) {
case map[interface{}]interface{}: case map[interface{}]interface{}:
// nested map: cast and recursively insensitivise // nested map: cast and recursively insensitivise
val = cast.ToStringMap(val) val = cast.ToStringMap(val)
insensitiviseMap(val.(map[string]interface{})) insensitiviseMap(val.(map[string]interface{}))
case map[string]interface{}: case map[string]interface{}:
// nested map: recursively insensitivise // nested map: recursively insensitivise
insensitiviseMap(val.(map[string]interface{})) insensitiviseMap(v)
} }
lower := strings.ToLower(key) lower := strings.ToLower(key)

View file

@ -491,13 +491,13 @@ func (v *Viper) searchMap(source map[string]interface{}, path []string) interfac
} }
// Nested case // Nested case
switch next.(type) { switch n := next.(type) {
case map[interface{}]interface{}: case map[interface{}]interface{}:
return v.searchMap(cast.ToStringMap(next), path[1:]) return v.searchMap(cast.ToStringMap(next), path[1:])
case map[string]interface{}: case map[string]interface{}:
// Type assertion is safe here since it is only reached // Type assertion is safe here since it is only reached
// if the type of `next` is the same as the type being asserted // 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: default:
// got a value but nested key expected, return "nil" for not found // got a value but nested key expected, return "nil" for not found
return nil return nil
@ -535,13 +535,13 @@ func (v *Viper) searchMapWithPathPrefixes(source map[string]interface{}, path []
// Nested case // Nested case
var val interface{} var val interface{}
switch next.(type) { switch n := next.(type) {
case map[interface{}]interface{}: case map[interface{}]interface{}:
val = v.searchMapWithPathPrefixes(cast.ToStringMap(next), path[i:]) val = v.searchMapWithPathPrefixes(cast.ToStringMap(next), path[i:])
case map[string]interface{}: case map[string]interface{}:
// Type assertion is safe here since it is only reached // Type assertion is safe here since it is only reached
// if the type of `next` is the same as the type being asserted // 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: default:
// got a value but nested key expected, do nothing and look for next prefix // 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 { for k, val := range m {
fullKey := prefix + k fullKey := prefix + k
switch val.(type) { switch v := val.(type) {
case map[string]interface{}: case map[string]interface{}:
m2 = val.(map[string]interface{}) m2 = v
case map[interface{}]interface{}: case map[interface{}]interface{}:
m2 = cast.ToStringMap(val) m2 = cast.ToStringMap(val)
default: default: