This commit is contained in:
Albert Le Batteux 2023-09-14 23:42:27 -04:00 committed by GitHub
commit 5e81c4f084
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 0 deletions

View file

@ -551,6 +551,7 @@ The following functions and methods exist:
* `GetIntSlice(key string) : []int`
* `GetString(key string) : string`
* `GetStringMap(key string) : map[string]interface{}`
* `GetStringMapStruct(key string) : map[string]struct{}`
* `GetStringMapString(key string) : map[string]string`
* `GetStringSlice(key string) : []string`
* `GetTime(key string) : time.Time`

View file

@ -1065,6 +1065,12 @@ func (v *Viper) GetStringSlice(key string) []string {
return cast.ToStringSlice(v.Get(key))
}
// GetStringMapStruct returns the value associated with the key as a slice of strings.
func GetStringMapStruct(key string) map[string]struct{} { return v.GetStringMapStruct(key) }
func (v *Viper) GetStringMapStruct(key string) map[string]struct{} {
return cast.ToStringMapStruct(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) }

View file

@ -2079,6 +2079,10 @@ func TestMergeConfig(t *testing.T) {
t.Fatalf("len(world) != 4, = %d", len(world))
}
if world := v.GetStringMapStruct("hello.world"); len(world) != 4 {
t.Fatalf("len(world) != 4, = %d, %#v", len(world), world)
}
if fu := v.GetString("fu"); fu != "" {
t.Fatalf("fu != \"\", = %s", fu)
}