diff --git a/util.go b/util.go index b788969..7707360 100644 --- a/util.go +++ b/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) diff --git a/viper.go b/viper.go index a8f84b5..1044946 100644 --- a/viper.go +++ b/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 +}