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
4
viper.go
4
viper.go
|
@ -424,8 +424,12 @@ func (v *Viper) searchMap(source map[string]interface{}, path []string) interfac
|
|||
// if the type of `next` is the same as the type being asserted
|
||||
return v.searchMap(next.(map[string]interface{}), path[1:])
|
||||
default:
|
||||
if len(path) == 1 {
|
||||
return next
|
||||
}
|
||||
// got a value but nested key expected, return "nil" for not found
|
||||
return nil
|
||||
}
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue