mirror of
https://github.com/spf13/viper
synced 2024-12-22 19:47:01 +00:00
Merge branch 'master' into fixed_68_73_83
This commit is contained in:
commit
7a8c6fea79
3 changed files with 19 additions and 11 deletions
|
@ -1,6 +1,5 @@
|
|||
language: go
|
||||
go:
|
||||
- 1.2
|
||||
- 1.3
|
||||
- release
|
||||
- tip
|
||||
|
|
9
viper.go
9
viper.go
|
@ -325,9 +325,10 @@ func (v *Viper) AddSecureRemoteProvider(provider, endpoint, path, secretkeyring
|
|||
if provider != "" && endpoint != "" {
|
||||
jww.INFO.Printf("adding %s:%s to remote provider list", provider, endpoint)
|
||||
rp := &defaultRemoteProvider{
|
||||
endpoint: endpoint,
|
||||
provider: provider,
|
||||
path: path,
|
||||
endpoint: endpoint,
|
||||
provider: provider,
|
||||
path: path,
|
||||
secretKeyring: secretkeyring,
|
||||
}
|
||||
if !v.providerPathExists(rp) {
|
||||
v.remoteProviders = append(v.remoteProviders, rp)
|
||||
|
@ -353,6 +354,8 @@ func (v *Viper) searchMap(source map[string]interface{}, path []string) interfac
|
|||
|
||||
if next, ok := source[path[0]]; ok {
|
||||
switch next.(type) {
|
||||
case map[interface{}]interface{}:
|
||||
return v.searchMap(cast.ToStringMap(next), path[1:])
|
||||
case map[string]interface{}:
|
||||
// Type assertion is safe here since it is only reached
|
||||
// if the type of `next` is the same as the type being asserted
|
||||
|
|
|
@ -30,6 +30,8 @@ hobbies:
|
|||
clothing:
|
||||
jacket: leather
|
||||
trousers: denim
|
||||
pants:
|
||||
size: large
|
||||
age: 35
|
||||
eyes : brown
|
||||
beard: true
|
||||
|
@ -208,7 +210,7 @@ func TestMarshalling(t *testing.T) {
|
|||
assert.False(t, InConfig("state"))
|
||||
assert.Equal(t, "steve", Get("name"))
|
||||
assert.Equal(t, []interface{}{"skateboarding", "snowboarding", "go"}, Get("hobbies"))
|
||||
assert.Equal(t, map[interface{}]interface{}{"jacket": "leather", "trousers": "denim"}, Get("clothing"))
|
||||
assert.Equal(t, map[interface{}]interface{}{"jacket": "leather", "trousers": "denim", "pants": map[interface{}]interface{}{"size": "large"}}, Get("clothing"))
|
||||
assert.Equal(t, 35, Get("age"))
|
||||
}
|
||||
|
||||
|
@ -348,7 +350,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", "pants": map[interface{}]interface{}{"size": "large"}}, "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()
|
||||
|
@ -568,11 +570,15 @@ func TestFindsNestedKeys(t *testing.T) {
|
|||
"clothing": map[interface{}]interface{}{
|
||||
"jacket": "leather",
|
||||
"trousers": "denim",
|
||||
"pants": map[interface{}]interface{}{
|
||||
"size": "large",
|
||||
},
|
||||
},
|
||||
"clothing.jacket": "leather",
|
||||
"clothing.trousers": "denim",
|
||||
"owner.dob": dob,
|
||||
"beard": true,
|
||||
"clothing.jacket": "leather",
|
||||
"clothing.pants.size": "large",
|
||||
"clothing.trousers": "denim",
|
||||
"owner.dob": dob,
|
||||
"beard": true,
|
||||
}
|
||||
|
||||
for key, expectedValue := range expected {
|
||||
|
@ -592,7 +598,7 @@ func TestReadBufConfig(t *testing.T) {
|
|||
assert.False(t, v.InConfig("state"))
|
||||
assert.Equal(t, "steve", v.Get("name"))
|
||||
assert.Equal(t, []interface{}{"skateboarding", "snowboarding", "go"}, v.Get("hobbies"))
|
||||
assert.Equal(t, map[interface{}]interface{}{"jacket": "leather", "trousers": "denim"}, v.Get("clothing"))
|
||||
assert.Equal(t, map[interface{}]interface{}{"jacket": "leather", "trousers": "denim", "pants": map[interface{}]interface{}{"size": "large"}}, v.Get("clothing"))
|
||||
assert.Equal(t, 35, v.Get("age"))
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue