mirror of https://github.com/spf13/viper.git
add sub viper list
This commit is contained in:
parent
15738813a0
commit
81806461a8
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
18
viper.go
18
viper.go
|
@ -664,6 +664,24 @@ func (v *Viper) Sub(key string) *Viper {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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.
|
// GetString returns the value associated with the key as a string.
|
||||||
func GetString(key string) string { return v.GetString(key) }
|
func GetString(key string) string { return v.GetString(key) }
|
||||||
func (v *Viper) GetString(key string) string {
|
func (v *Viper) GetString(key string) string {
|
||||||
|
|
Loading…
Reference in New Issue