mirror of https://github.com/spf13/viper.git
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:
parent
d493c32b69
commit
32aa319187
9
viper.go
9
viper.go
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue