refactor: move all settings code to a getter

Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
This commit is contained in:
Mark Sagi-Kazar 2023-12-05 15:17:54 +01:00 committed by Márk Sági-Kazár
parent c4dcd31f68
commit 6ea31ae4ca
1 changed files with 5 additions and 1 deletions

View File

@ -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,