if config type is already set, ignore file extension and use the saved config type

e.g. if viper.SetConfigType("yaml") was previously called, yaml will be used as
config format, even if the file is called XXX.conf, instead of XXXX.yaml
This commit is contained in:
cmohrb 2018-07-13 15:55:31 +02:00
parent d493c32b69
commit 32aa319187

View file

@ -1245,7 +1245,14 @@ func (v *Viper) writeConfig(filename string, force bool) error {
if len(ext) <= 1 { if len(ext) <= 1 {
return fmt.Errorf("Filename: %s requires valid extension.", filename) 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) { if !stringInSlice(configType, SupportedExts) {
return UnsupportedConfigError(configType) return UnsupportedConfigError(configType)
} }