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:
Christian Mohrbacher 2018-07-13 15:55:31 +02:00
parent d493c32b69
commit 65e8f0b086

View file

@ -1245,7 +1245,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)
}