mirror of
https://github.com/spf13/viper
synced 2025-05-06 12:17:18 +00:00
Fix: Get() returns nil when nested element not found
If foo.bar is defined but foo.bar.baz isn't, then v.Get("foo.bar.baz") returns nil. v.searchMap() modified for this purpose.
This commit is contained in:
parent
fd1ed93339
commit
4db0eb0976
1 changed files with 5 additions and 1 deletions
6
viper.go
6
viper.go
|
@ -424,7 +424,11 @@ func (v *Viper) searchMap(source map[string]interface{}, path []string) interfac
|
||||||
// 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(next.(map[string]interface{}), path[1:])
|
||||||
default:
|
default:
|
||||||
return next
|
if len(path) == 1 {
|
||||||
|
return next
|
||||||
|
}
|
||||||
|
// got a value but nested key expected, return "nil" for not found
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Add table
Reference in a new issue