From 347c770cfb846fb3692263c3de5682edf8a32ac0 Mon Sep 17 00:00:00 2001 From: Kiril Zvezdarov Date: Mon, 16 Feb 2015 23:42:08 -0500 Subject: [PATCH 1/2] Marshal now gets the map via the AllSettings method --- viper.go | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/viper.go b/viper.go index 89834b7..b48b31b 100644 --- a/viper.go +++ b/viper.go @@ -313,23 +313,10 @@ func (v *viper) MarshalKey(key string, rawVal interface{}) error { // Marshals the config into a Struct func Marshal(rawVal interface{}) error { return v.Marshal(rawVal) } func (v *viper) Marshal(rawVal interface{}) error { - err := mapstructure.Decode(v.defaults, rawVal) + err := mapstructure.WeakDecode(v.AllSettings(), rawVal) if err != nil { return err } - err = mapstructure.Decode(v.config, rawVal) - if err != nil { - return err - } - err = mapstructure.Decode(v.override, rawVal) - if err != nil { - return err - } - err = mapstructure.Decode(v.kvstore, rawVal) - if err != nil { - return err - } - v.insensativiseMaps() return nil From 888e1e5f0ba0c810df8e776a2e5e6d9b19878085 Mon Sep 17 00:00:00 2001 From: Kiril Zvezdarov Date: Mon, 16 Feb 2015 23:42:29 -0500 Subject: [PATCH 2/2] Added keys from env and pflags to AllKeys --- viper.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/viper.go b/viper.go index b48b31b..c00b4d5 100644 --- a/viper.go +++ b/viper.go @@ -633,6 +633,14 @@ func (v *viper) AllKeys() []string { m[key] = struct{}{} } + for key, _ := range v.env { + m[key] = struct{}{} + } + + for key, _ := range v.pflags { + m[key] = struct{}{} + } + for key, _ := range v.override { m[key] = struct{}{} }