Sort keys before looping through them to avoid overwriting

Signed-off-by: Sonny Alves Dias <sonny.dias@superevilmegacorp.com>
This commit is contained in:
Sonny Alves Dias 2023-12-16 12:05:51 +08:00
parent 0b0a1104ba
commit 54541f4c03

View file

@ -28,6 +28,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"reflect" "reflect"
"sort"
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
@ -2138,6 +2139,7 @@ func (v *Viper) AllSettings() map[string]any {
func (v *Viper) getSettings(keys []string) map[string]any { func (v *Viper) getSettings(keys []string) map[string]any {
m := map[string]any{} m := map[string]any{}
sort.Strings(keys)
// start from the list of keys, and construct the map one value at a time // start from the list of keys, and construct the map one value at a time
for _, k := range keys { for _, k := range keys {
value := v.Get(k) value := v.Get(k)