mirror of https://github.com/spf13/viper.git
Make the map in MergeConfigMap case insensitive
This commit is contained in:
parent
41cd1c3aa3
commit
6d33b5a963
2
viper.go
2
viper.go
|
@ -1267,11 +1267,13 @@ func (v *Viper) MergeConfig(in io.Reader) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// MergeConfigMap merges the configuration from the map given with an existing config.
|
// MergeConfigMap merges the configuration from the map given with an existing config.
|
||||||
|
// Note that the map given may be modified.
|
||||||
func MergeConfigMap(cfg map[string]interface{}) error { return v.MergeConfigMap(cfg) }
|
func MergeConfigMap(cfg map[string]interface{}) error { return v.MergeConfigMap(cfg) }
|
||||||
func (v *Viper) MergeConfigMap(cfg map[string]interface{}) error {
|
func (v *Viper) MergeConfigMap(cfg map[string]interface{}) error {
|
||||||
if v.config == nil {
|
if v.config == nil {
|
||||||
v.config = make(map[string]interface{})
|
v.config = make(map[string]interface{})
|
||||||
}
|
}
|
||||||
|
insensitiviseMap(cfg)
|
||||||
mergeMaps(cfg, v.config, nil)
|
mergeMaps(cfg, v.config, nil)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -1252,8 +1252,11 @@ func TestMergeConfigMap(t *testing.T) {
|
||||||
assert(37890)
|
assert(37890)
|
||||||
|
|
||||||
update := map[string]interface{}{
|
update := map[string]interface{}{
|
||||||
"hello": map[string]interface{}{
|
"Hello": map[string]interface{}{
|
||||||
"pop": 1234,
|
"Pop": 1234,
|
||||||
|
},
|
||||||
|
"World": map[interface{}]interface{}{
|
||||||
|
"Rock": 345,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1261,6 +1264,10 @@ func TestMergeConfigMap(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if rock := v.GetInt("world.rock"); rock != 345 {
|
||||||
|
t.Fatal("Got rock:", rock)
|
||||||
|
}
|
||||||
|
|
||||||
assert(1234)
|
assert(1234)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue