diff --git a/README.md b/README.md index f451881..998ccff 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/viper.go b/viper.go index 097483b..67996c3 100644 --- a/viper.go +++ b/viper.go @@ -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) } diff --git a/viper_test.go b/viper_test.go index ccc9225..0664ba7 100644 --- a/viper_test.go +++ b/viper_test.go @@ -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) }