mirror of
https://github.com/spf13/viper
synced 2024-12-24 12:37:02 +00:00
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
1 changed files with 8 additions and 1 deletions
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 a new issue