mirror of https://github.com/spf13/viper.git
Compare commits
4 Commits
49cd39ea07
...
c6ed40d26b
Author | SHA1 | Date |
---|---|---|
yangheng | c6ed40d26b | |
yangheng | 4ff42e3b4b | |
yangheng | 0648a0fafe | |
yangheng | 81806461a8 |
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…
Reference in New Issue