From 8d9577a72e57989b539c3cb7d7691673ed422af1 Mon Sep 17 00:00:00 2001 From: Kiril Zvezdarov Date: Fri, 1 May 2015 16:18:03 -0400 Subject: [PATCH] Recursively insensitivize the configuration structures --- util.go | 5 +++++ viper_test.go | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/util.go b/util.go index 7c5d21a..6fef1a4 100644 --- a/util.go +++ b/util.go @@ -17,6 +17,7 @@ import ( "io" "os" "path/filepath" + "reflect" "runtime" "strings" "unicode" @@ -35,6 +36,10 @@ func insensitiviseMap(m map[string]interface{}) { delete(m, key) m[lower] = val } + + if val != nil && reflect.TypeOf(val).Kind() == reflect.Map { + insensitiviseMap(cast.ToStringMap(val)) + } } } diff --git a/viper_test.go b/viper_test.go index 76ec0d2..1039039 100644 --- a/viper_test.go +++ b/viper_test.go @@ -304,7 +304,7 @@ func TestAllKeys(t *testing.T) { ks := sort.StringSlice{"title", "newkey", "owner", "name", "beard", "ppu", "batters", "hobbies", "clothing", "age", "hacker", "id", "type", "eyes", "p_id", "p_ppu", "p_batters.batter.type", "p_type", "p_name"} dob, _ := time.Parse(time.RFC3339, "1979-05-27T07:32:00Z") - all := map[string]interface{}{"owner": map[string]interface{}{"organization": "MongoDB", "Bio": "MongoDB Chief Developer Advocate & Hacker at Large", "dob": dob}, "title": "TOML Example", "ppu": 0.55, "eyes": "brown", "clothing": map[interface{}]interface{}{"trousers": "denim", "jacket": "leather"}, "id": "0001", "batters": map[string]interface{}{"batter": []interface{}{map[string]interface{}{"type": "Regular"}, map[string]interface{}{"type": "Chocolate"}, map[string]interface{}{"type": "Blueberry"}, map[string]interface{}{"type": "Devil's Food"}}}, "hacker": true, "beard": true, "hobbies": []interface{}{"skateboarding", "snowboarding", "go"}, "age": 35, "type": "donut", "newkey": "remote", "name": "Cake", "p_id": "0001", "p_ppu": "0.55", "p_name": "Cake", "p_batters.batter.type": "Regular", "p_type": "donut"} + all := map[string]interface{}{"owner": map[string]interface{}{"organization": "MongoDB", "bio": "MongoDB Chief Developer Advocate & Hacker at Large", "dob": dob}, "title": "TOML Example", "ppu": 0.55, "eyes": "brown", "clothing": map[interface{}]interface{}{"trousers": "denim", "jacket": "leather"}, "id": "0001", "batters": map[string]interface{}{"batter": []interface{}{map[string]interface{}{"type": "Regular"}, map[string]interface{}{"type": "Chocolate"}, map[string]interface{}{"type": "Blueberry"}, map[string]interface{}{"type": "Devil's Food"}}}, "hacker": true, "beard": true, "hobbies": []interface{}{"skateboarding", "snowboarding", "go"}, "age": 35, "type": "donut", "newkey": "remote", "name": "Cake", "p_id": "0001", "p_ppu": "0.55", "p_name": "Cake", "p_batters.batter.type": "Regular", "p_type": "donut"} var allkeys sort.StringSlice allkeys = AllKeys() @@ -512,10 +512,10 @@ func TestFindsNestedKeys(t *testing.T) { "age": 35, "owner": map[string]interface{}{ "organization": "MongoDB", - "Bio": "MongoDB Chief Developer Advocate & Hacker at Large", + "bio": "MongoDB Chief Developer Advocate & Hacker at Large", "dob": dob, }, - "owner.Bio": "MongoDB Chief Developer Advocate & Hacker at Large", + "owner.bio": "MongoDB Chief Developer Advocate & Hacker at Large", "type": "donut", "id": "0001", "name": "Cake",