mirror of
https://github.com/spf13/viper
synced 2025-05-07 04:37:20 +00:00
fixed typeSwitchVar warnings
This commit is contained in:
parent
62edee3196
commit
f5346596bf
3 changed files with 10 additions and 10 deletions
|
@ -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
|
||||
|
|
4
util.go
4
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)
|
||||
|
|
12
viper.go
12
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:
|
||||
|
|
Loading…
Add table
Reference in a new issue