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
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

View file

@ -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)

View file

@ -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: