mirror of
https://github.com/spf13/viper
synced 2024-12-22 11:37:02 +00:00
parent
382f87b929
commit
670c42a85b
2 changed files with 7 additions and 0 deletions
4
viper.go
4
viper.go
|
@ -532,6 +532,10 @@ func Sub(key string) *Viper { return v.Sub(key) }
|
|||
func (v *Viper) Sub(key string) *Viper {
|
||||
subv := New()
|
||||
data := v.Get(key)
|
||||
if data == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if reflect.TypeOf(data).Kind() == reflect.Map {
|
||||
subv.config = cast.ToStringMap(data)
|
||||
return subv
|
||||
|
|
|
@ -760,6 +760,9 @@ func TestSub(t *testing.T) {
|
|||
|
||||
subv = v.Sub("clothing.pants.size")
|
||||
assert.Equal(t, subv, (*Viper)(nil))
|
||||
|
||||
subv = v.Sub("missing.key")
|
||||
assert.Equal(t, subv, (*Viper)(nil))
|
||||
}
|
||||
|
||||
var yamlMergeExampleTgt = []byte(`
|
||||
|
|
Loading…
Reference in a new issue