This commit is contained in:
Maxim Krasilnikov 2017-07-23 05:52:46 +00:00 committed by GitHub
commit ba9d8fe52a
2 changed files with 37 additions and 0 deletions

View file

@ -691,6 +691,12 @@ func (v *Viper) GetStringSlice(key string) []string {
return cast.ToStringSlice(v.Get(key))
}
// GetIntSlice returns the value associated with the key as a slice of ints.
func GetIntSlice(key string) []int { return v.GetIntSlice(key) }
func (v *Viper) GetIntSlice(key string) []int {
return cast.ToIntSlice(v.Get(key))
}
// GetStringMap returns the value associated with the key as a map of interfaces.
func GetStringMap(key string) map[string]interface{} { return v.GetStringMap(key) }
func (v *Viper) GetStringMap(key string) map[string]interface{} {

View file

@ -856,6 +856,10 @@ hello:
- uk
- fr
- de
groups:
- 1
- 2
- 3
`)
var yamlMergeExampleSrc = []byte(`
@ -865,6 +869,9 @@ hello:
universe:
- mw
- ad
ages:
- 21
- 34
fu: bar
`)
@ -891,6 +898,10 @@ func TestMergeConfig(t *testing.T) {
t.Fatalf("len(world) != 4, = %d", len(world))
}
if groups := v.GetIntSlice("hello.groups"); len(groups) != 3 {
t.Fatalf("len(groups) != 3, = %d", len(groups))
}
if fu := v.GetString("fu"); fu != "" {
t.Fatalf("fu != \"\", = %s", fu)
}
@ -919,6 +930,14 @@ func TestMergeConfig(t *testing.T) {
t.Fatalf("len(universe) != 2, = %d", len(universe))
}
if groups := v.GetIntSlice("hello.groups"); len(groups) != 3 {
t.Fatalf("len(groups) != 3, = %d", len(groups))
}
if ages := v.GetIntSlice("hello.ages"); len(ages) != 2 {
t.Fatalf("len(ages) != 2, = %d", len(ages))
}
if fu := v.GetString("fu"); fu != "bar" {
t.Fatalf("fu != \"bar\", = %s", fu)
}
@ -939,6 +958,10 @@ func TestMergeConfigNoMerge(t *testing.T) {
t.Fatalf("len(world) != 4, = %d", len(world))
}
if groups := v.GetIntSlice("hello.groups"); len(groups) != 3 {
t.Fatalf("len(groups) != 3, = %d", len(groups))
}
if fu := v.GetString("fu"); fu != "" {
t.Fatalf("fu != \"\", = %s", fu)
}
@ -959,6 +982,14 @@ func TestMergeConfigNoMerge(t *testing.T) {
t.Fatalf("len(universe) != 2, = %d", len(universe))
}
if groups := v.GetIntSlice("hello.groups"); len(groups) != 0 {
t.Fatalf("len(groups) != 0, = %d", len(groups))
}
if ages := v.GetIntSlice("hello.ages"); len(ages) != 2 {
t.Fatalf("len(groups) != 2, = %d", len(ages))
}
if fu := v.GetString("fu"); fu != "bar" {
t.Fatalf("fu != \"bar\", = %s", fu)
}