From 6ea31ae4ca569f048d53a06e91574f1ebe4b0225 Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Tue, 5 Dec 2023 15:17:54 +0100 Subject: [PATCH] refactor: move all settings code to a getter Signed-off-by: Mark Sagi-Kazar --- viper.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/viper.go b/viper.go index 7de2e78..5cbcc9f 100644 --- a/viper.go +++ b/viper.go @@ -2098,9 +2098,13 @@ outer: func AllSettings() map[string]any { return v.AllSettings() } func (v *Viper) AllSettings() map[string]any { + return v.getSettings(v.AllKeys()) +} + +func (v *Viper) getSettings(keys []string) map[string]any { m := map[string]any{} // start from the list of keys, and construct the map one value at a time - for _, k := range v.AllKeys() { + for _, k := range keys { value := v.Get(k) if value == nil { // should not happen, since AllKeys() returns only keys holding a value,