From 963ca4f768e9d4d1bcb3fb22455e0f7bfc4d5ea6 Mon Sep 17 00:00:00 2001 From: Alexandre Bourget Date: Fri, 8 Jan 2016 23:53:37 -0500 Subject: [PATCH 1/3] Expose the default Viper instance through methods. To open up programming switching of configs, related to https://github.com/spf13/hugo/pull/1734 --- viper.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/viper.go b/viper.go index 389a58e..087bcad 100644 --- a/viper.go +++ b/viper.go @@ -174,6 +174,18 @@ func New() *Viper { return v } +// DefaultConfig retrieves the default Viper instance. To be loaded +// later with SetDefaultConfig. +func DefaultConfig() *Viper { + return v +} + +// SetDefaultConfig applies this Viper instance as the default. Used +// when calling the functions defined in the viper package. +func SetDefaultConfig(conf *Viper) { + v = conf +} + // Intended for testing, will reset all to default settings. // In the public interface for the viper package so applications // can use it in their testing as well. From 7b7d1442ac901906c522c875db9419c5f1dad471 Mon Sep 17 00:00:00 2001 From: Alexandre Bourget Date: Sat, 9 Jan 2016 00:25:12 -0500 Subject: [PATCH 2/3] Simplified to `Default` and `SetDefault` --- viper.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/viper.go b/viper.go index 087bcad..c11c06a 100644 --- a/viper.go +++ b/viper.go @@ -174,15 +174,15 @@ func New() *Viper { return v } -// DefaultConfig retrieves the default Viper instance. To be loaded -// later with SetDefaultConfig. -func DefaultConfig() *Viper { +// Default retrieves the default Viper instance. To be loaded later +// with SetDefault. +func Default() *Viper { return v } -// SetDefaultConfig applies this Viper instance as the default. Used -// when calling the functions defined in the viper package. -func SetDefaultConfig(conf *Viper) { +// SetDefault applies this Viper instance as the default. Used when +// calling the functions defined in the viper package. +func SetDefault(conf *Viper) { v = conf } From 70685607d856e63727a3cde53ea7f3733cc8b63e Mon Sep 17 00:00:00 2001 From: Alexandre Bourget Date: Sat, 9 Jan 2016 00:46:41 -0500 Subject: [PATCH 3/3] Whoops, overrode the original SetDefault ! didn't chekc much heh! --- viper.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/viper.go b/viper.go index c11c06a..087bcad 100644 --- a/viper.go +++ b/viper.go @@ -174,15 +174,15 @@ func New() *Viper { return v } -// Default retrieves the default Viper instance. To be loaded later -// with SetDefault. -func Default() *Viper { +// DefaultConfig retrieves the default Viper instance. To be loaded +// later with SetDefaultConfig. +func DefaultConfig() *Viper { return v } -// SetDefault applies this Viper instance as the default. Used when -// calling the functions defined in the viper package. -func SetDefault(conf *Viper) { +// SetDefaultConfig applies this Viper instance as the default. Used +// when calling the functions defined in the viper package. +func SetDefaultConfig(conf *Viper) { v = conf }