From 88c1d9fbd919ced64373cfd54d26210dfeb8e37d Mon Sep 17 00:00:00 2001 From: Brice Fernandes Date: Mon, 9 Jul 2018 18:41:40 +0100 Subject: [PATCH 1/2] Expose MarshalWriter publicly --- viper.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/viper.go b/viper.go index 907a102..292e70d 100644 --- a/viper.go +++ b/viper.go @@ -1329,11 +1329,13 @@ func (v *Viper) unmarshalReader(in io.Reader, c map[string]interface{}) error { return nil } -// Marshal a map into Writer. -func marshalWriter(f afero.File, configType string) error { +// MarshalWriter will marshal a map into Writer for the default config +func MarshalWriter(f afero.File, configType string) error { return v.marshalWriter(f, configType) } -func (v *Viper) marshalWriter(f afero.File, configType string) error { + +// MarshalWriter will marshal a map into Writer. +func (v *Viper) MarshalWriter(f afero.File, configType string) error { c := v.AllSettings() switch configType { case "json": From 59bd5de38441192077d86c580288b349590298c0 Mon Sep 17 00:00:00 2001 From: Brice Fernandes Date: Mon, 9 Jul 2018 18:49:46 +0100 Subject: [PATCH 2/2] Update invocations --- viper.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/viper.go b/viper.go index 292e70d..651fdb3 100644 --- a/viper.go +++ b/viper.go @@ -1266,7 +1266,7 @@ func (v *Viper) writeConfig(filename string, force bool) error { if err != nil { return err } - return v.marshalWriter(f, configType) + return v.MarshalWriter(f, configType) } // Unmarshal a Reader into a map. @@ -1331,7 +1331,7 @@ func (v *Viper) unmarshalReader(in io.Reader, c map[string]interface{}) error { // MarshalWriter will marshal a map into Writer for the default config func MarshalWriter(f afero.File, configType string) error { - return v.marshalWriter(f, configType) + return v.MarshalWriter(f, configType) } // MarshalWriter will marshal a map into Writer.