From 96569713891109457a66a88a88194b5af51c5eac Mon Sep 17 00:00:00 2001 From: Kristin Laemmert Date: Wed, 20 Dec 2017 12:05:47 -0800 Subject: [PATCH] use v.getConfigType to determine config type in WriteConfig --- viper.go | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/viper.go b/viper.go index ad8a037..7359ca2 100644 --- a/viper.go +++ b/viper.go @@ -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{}) } @@ -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.