Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue 427: use v.getConfigType to determine config type in WriteConfig #428

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 5 additions & 8 deletions viper.go
Original file line number Diff line number Diff line change
Expand Up @@ -1235,14 +1235,11 @@ func (v *Viper) SafeWriteConfigAs(filename string) error {
func writeConfig(filename string, force bool) error { return v.writeConfig(filename, force) }
func (v *Viper) writeConfig(filename string, force bool) error {
jww.INFO.Println("Attempting to write configuration to file.")
ext := filepath.Ext(filename)
if len(ext) <= 1 {
return fmt.Errorf("Filename: %s requires valid extension.", filename)
}
configType := ext[1:]
if !stringInSlice(configType, SupportedExts) {
return UnsupportedConfigError(configType)

if !stringInSlice(v.getConfigType(), SupportedExts) {
return UnsupportedConfigError(v.getConfigType())
}

if v.config == nil {
v.config = make(map[string]interface{})
}
Expand All @@ -1260,7 +1257,7 @@ func (v *Viper) writeConfig(filename string, force bool) error {
if err != nil {
return err
}
return v.marshalWriter(f, configType)
return v.marshalWriter(f, v.getConfigType())
}

// Unmarshal a Reader into a map.
Expand Down