From 32aa3191878d98bdb37f331dff0856f553d756c9 Mon Sep 17 00:00:00 2001 From: cmohrb Date: Fri, 13 Jul 2018 15:55:31 +0200 Subject: [PATCH] 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 --- viper.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/viper.go b/viper.go index 907a102..db2d6d6 100644 --- a/viper.go +++ b/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) }