mirror of
https://github.com/spf13/viper
synced 2025-05-10 22:27:18 +00:00
Merge 9656971389
into 3349bd9cc2
This commit is contained in:
commit
b4264bedbd
1 changed files with 5 additions and 8 deletions
13
viper.go
13
viper.go
|
@ -1346,14 +1346,11 @@ func (v *Viper) SafeWriteConfigAs(filename string) error {
|
||||||
func writeConfig(filename string, force bool) error { return v.writeConfig(filename, force) }
|
func writeConfig(filename string, force bool) error { return v.writeConfig(filename, force) }
|
||||||
func (v *Viper) writeConfig(filename string, force bool) error {
|
func (v *Viper) writeConfig(filename string, force bool) error {
|
||||||
jww.INFO.Println("Attempting to write configuration to file.")
|
jww.INFO.Println("Attempting to write configuration to file.")
|
||||||
ext := filepath.Ext(filename)
|
|
||||||
if len(ext) <= 1 {
|
if !stringInSlice(v.getConfigType(), SupportedExts) {
|
||||||
return fmt.Errorf("Filename: %s requires valid extension.", filename)
|
return UnsupportedConfigError(v.getConfigType())
|
||||||
}
|
|
||||||
configType := ext[1:]
|
|
||||||
if !stringInSlice(configType, SupportedExts) {
|
|
||||||
return UnsupportedConfigError(configType)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if v.config == nil {
|
if v.config == nil {
|
||||||
v.config = make(map[string]interface{})
|
v.config = make(map[string]interface{})
|
||||||
}
|
}
|
||||||
|
@ -1371,7 +1368,7 @@ func (v *Viper) writeConfig(filename string, force bool) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return v.marshalWriter(f, configType)
|
return v.marshalWriter(f, v.getConfigType())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unmarshal a Reader into a map.
|
// Unmarshal a Reader into a map.
|
||||||
|
|
Loading…
Add table
Reference in a new issue