Fixed #115: Added code in the find method to search for nested configuration parameters
diff --git a/viper.go b/viper.go
index 5afed24..d9c5e67 100644
--- a/viper.go
+++ b/viper.go
@@ -657,6 +657,20 @@
return val
}
+ // Test for nested config parameter
+ if strings.Contains(key, v.keyDelim) {
+ path := strings.Split(key, v.keyDelim)
+
+ source := v.find(path[0])
+ if source != nil {
+ if reflect.TypeOf(source).Kind() == reflect.Map {
+ val := v.searchMap(cast.ToStringMap(source), path[1:])
+ jww.TRACE.Println(key, "found in nested config:", val)
+ return val
+ }
+ }
+ }
+
val, exists = v.kvstore[key]
if exists {
jww.TRACE.Println(key, "found in key/value store:", val)
diff --git a/viper_test.go b/viper_test.go
index 6b9db6e..d9aae00 100644
--- a/viper_test.go
+++ b/viper_test.go
@@ -199,6 +199,15 @@
func TestDefault(t *testing.T) {
SetDefault("age", 45)
assert.Equal(t, 45, Get("age"))
+
+ SetDefault("clothing.jacket", "slacks")
+ assert.Equal(t, "slacks", Get("clothing.jacket"))
+
+ SetConfigType("yaml")
+ err := ReadConfig(bytes.NewBuffer(yamlExample))
+
+ assert.NoError(t, err)
+ assert.Equal(t, "leather", Get("clothing.jacket"))
}
func TestUnmarshalling(t *testing.T) {