mirror of
https://github.com/spf13/viper
synced 2025-05-07 20:57:18 +00:00
Merge 4f738d6f3f
into f2cbaea4c2
This commit is contained in:
commit
7af5276560
2 changed files with 38 additions and 1 deletions
7
util.go
7
util.go
|
@ -76,6 +76,13 @@ func insensitiviseMap(m map[string]interface{}) {
|
|||
case map[string]interface{}:
|
||||
// nested map: recursively insensitivise
|
||||
insensitiviseMap(val.(map[string]interface{}))
|
||||
case []interface{}:
|
||||
for _, x := range val.([]interface{}) {
|
||||
y, ok := x.(map[string]interface{})
|
||||
if ok {
|
||||
insensitiviseMap(y)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lower := strings.ToLower(key)
|
||||
|
|
32
viper.go
32
viper.go
|
@ -1417,7 +1417,14 @@ func (v *Viper) writeConfig(filename string, force bool) error {
|
|||
if len(ext) <= 1 {
|
||||
return fmt.Errorf("filename: %s requires valid extension", filename)
|
||||
}
|
||||
configType := ext[1:]
|
||||
|
||||
var configType string
|
||||
if v.configType == "" {
|
||||
configType = ext[1:]
|
||||
} else {
|
||||
configType = v.configType
|
||||
}
|
||||
|
||||
if !stringInSlice(configType, SupportedExts) {
|
||||
return UnsupportedConfigError(configType)
|
||||
}
|
||||
|
@ -2006,3 +2013,26 @@ func (v *Viper) Debug() {
|
|||
fmt.Printf("Config:\n%#v\n", v.config)
|
||||
fmt.Printf("Defaults:\n%#v\n", v.defaults)
|
||||
}
|
||||
|
||||
func SubSlice(key string) (out []*Viper) { return v.SubSlice(key) }
|
||||
func (v *Viper) SubSlice(key string) (out []*Viper) {
|
||||
data := v.Get(key)
|
||||
|
||||
if data == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if reflect.TypeOf(data).Kind() != reflect.Slice {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, elem := range data.([]interface{}) {
|
||||
subv := New()
|
||||
if reflect.TypeOf(elem).Kind() == reflect.Map {
|
||||
subv.config = cast.ToStringMap(elem)
|
||||
out = append(out, subv)
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue