mirror of
https://github.com/spf13/viper
synced 2025-04-27 15:57:19 +00:00
Merge ca33b081ee
into 1508a7ba44
This commit is contained in:
commit
1fac6c8cce
1 changed files with 19 additions and 0 deletions
19
viper.go
19
viper.go
|
@ -781,6 +781,25 @@ func (v *Viper) Sub(key string) *Viper {
|
|||
return nil
|
||||
}
|
||||
|
||||
//Sub list returns new Viper instance List representing a sub tree of this instance.
|
||||
func SubList(key string) []*Viper { return v.SubList(key) }
|
||||
func (v *Viper) SubList(key string) []*Viper {
|
||||
data := v.Get(key)
|
||||
if data == nil {
|
||||
return nil
|
||||
}
|
||||
var vList []*Viper
|
||||
if reflect.TypeOf(data).Kind() == reflect.Slice {
|
||||
for _, item := range data.([]interface{}) {
|
||||
subv := New()
|
||||
subv.config = cast.ToStringMap(item)
|
||||
vList = append(vList, subv)
|
||||
}
|
||||
return vList
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetString returns the value associated with the key as a string.
|
||||
func GetString(key string) string { return v.GetString(key) }
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue