mirror of
https://github.com/spf13/viper
synced 2025-05-07 20:57:18 +00:00
Merge 442af302ff
into c898f59d33
This commit is contained in:
commit
2662dc5e43
2 changed files with 25 additions and 1 deletions
5
viper.go
5
viper.go
|
@ -948,7 +948,10 @@ func (v *Viper) Sub(key string) *Viper {
|
|||
}
|
||||
|
||||
if reflect.TypeOf(data).Kind() == reflect.Map {
|
||||
subv.config = cast.ToStringMap(data)
|
||||
m := cast.ToStringMap(data)
|
||||
for k, v := range m {
|
||||
subv.config[strings.ToLower(k)] = v
|
||||
}
|
||||
return subv
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -53,6 +53,15 @@ var yamlExampleWithExtras = []byte(`Existing: true
|
|||
Bogus: true
|
||||
`)
|
||||
|
||||
var yamlExampleWithSubtreeCaps = []byte(`Hacker: true
|
||||
name: steve
|
||||
clothing:
|
||||
JACKET: leather
|
||||
TROUSERS: denim
|
||||
pants:
|
||||
size: large
|
||||
`)
|
||||
|
||||
type testUnmarshalExtra struct {
|
||||
Existing bool
|
||||
}
|
||||
|
@ -1908,6 +1917,18 @@ func TestWriteHiddenFile(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestSubWithCaps(t *testing.T) {
|
||||
v := New()
|
||||
v.SetConfigType("yaml")
|
||||
v.ReadConfig(bytes.NewBuffer(yamlExampleWithSubtreeCaps))
|
||||
|
||||
subv := v.Sub("clothing")
|
||||
assert.Equal(t, v.Get("clothing.JACKET"), subv.Get("jacket"))
|
||||
|
||||
subv = v.Sub("clothing.pants.size")
|
||||
assert.Equal(t, subv, (*Viper)(nil))
|
||||
}
|
||||
|
||||
var yamlMergeExampleTgt = []byte(`
|
||||
hello:
|
||||
pop: 37890
|
||||
|
|
Loading…
Add table
Reference in a new issue