mirror of
https://github.com/spf13/viper
synced 2024-11-04 20:27:02 +00:00
Add ToStringMapStruct()
This commit is contained in:
parent
aafc9e6bc7
commit
5f41252f95
3 changed files with 11 additions and 0 deletions
|
@ -432,6 +432,7 @@ The following functions and methods exist:
|
||||||
* `GetInt(key string) : int`
|
* `GetInt(key string) : int`
|
||||||
* `GetString(key string) : string`
|
* `GetString(key string) : string`
|
||||||
* `GetStringMap(key string) : map[string]interface{}`
|
* `GetStringMap(key string) : map[string]interface{}`
|
||||||
|
* `GetStringMapStruct(key string) : map[string]struct{}`
|
||||||
* `GetStringMapString(key string) : map[string]string`
|
* `GetStringMapString(key string) : map[string]string`
|
||||||
* `GetStringSlice(key string) : []string`
|
* `GetStringSlice(key string) : []string`
|
||||||
* `GetTime(key string) : time.Time`
|
* `GetTime(key string) : time.Time`
|
||||||
|
|
6
viper.go
6
viper.go
|
@ -712,6 +712,12 @@ func (v *Viper) GetStringSlice(key string) []string {
|
||||||
return cast.ToStringSlice(v.Get(key))
|
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.
|
// 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 GetStringMap(key string) map[string]interface{} { return v.GetStringMap(key) }
|
||||||
func (v *Viper) GetStringMap(key string) map[string]interface{} {
|
func (v *Viper) GetStringMap(key string) map[string]interface{} {
|
||||||
|
|
|
@ -1076,6 +1076,10 @@ func TestMergeConfig(t *testing.T) {
|
||||||
t.Fatalf("len(world) != 4, = %d", len(world))
|
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 != "" {
|
if fu := v.GetString("fu"); fu != "" {
|
||||||
t.Fatalf("fu != \"\", = %s", fu)
|
t.Fatalf("fu != \"\", = %s", fu)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue