forked from mirror/viper
parent
382f87b929
commit
670c42a85b
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 New Issue