mirror of https://github.com/spf13/viper.git
feat: copy keydelim from parent chart in viper.Sub()
This commit is contained in:
parent
ae564f05cb
commit
864a85aada
1
viper.go
1
viper.go
|
@ -774,6 +774,7 @@ func (v *Viper) Sub(key string) *Viper {
|
||||||
subv.automaticEnvApplied = v.automaticEnvApplied
|
subv.automaticEnvApplied = v.automaticEnvApplied
|
||||||
subv.envPrefix = v.envPrefix
|
subv.envPrefix = v.envPrefix
|
||||||
subv.envKeyReplacer = v.envKeyReplacer
|
subv.envKeyReplacer = v.envKeyReplacer
|
||||||
|
subv.keyDelim = v.keyDelim
|
||||||
subv.config = cast.ToStringMap(data)
|
subv.config = cast.ToStringMap(data)
|
||||||
return subv
|
return subv
|
||||||
}
|
}
|
||||||
|
|
|
@ -1681,6 +1681,17 @@ func TestSub(t *testing.T) {
|
||||||
assert.Equal(t, []string{"clothing", "pants"}, subv.parents)
|
assert.Equal(t, []string{"clothing", "pants"}, subv.parents)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSubWithKeyDelimiter(t *testing.T) {
|
||||||
|
v := NewWithOptions(KeyDelimiter("::"))
|
||||||
|
v.SetConfigType("yaml")
|
||||||
|
r := strings.NewReader(string(yamlExampleWithDot))
|
||||||
|
err := v.unmarshalReader(r, v.config)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
subv := v.Sub("emails")
|
||||||
|
assert.Equal(t, "01/02/03", subv.Get("steve@hacker.com::created"))
|
||||||
|
}
|
||||||
|
|
||||||
var jsonWriteExpected = []byte(`{
|
var jsonWriteExpected = []byte(`{
|
||||||
"batters": {
|
"batters": {
|
||||||
"batter": [
|
"batter": [
|
||||||
|
|
Loading…
Reference in New Issue