Sort keys returned by AllKeys in reverse order

This commit is contained in:
Dustin Long 2024-05-20 10:10:39 -04:00
parent d3bdf71242
commit 0b0114ad80
No known key found for this signature in database

View file

@ -29,6 +29,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"reflect" "reflect"
"sort"
"strings" "strings"
"time" "time"
@ -1801,9 +1802,20 @@ func (v *Viper) AllKeys() []string {
for x := range m { for x := range m {
a = append(a, x) a = append(a, x)
} }
return a sort.Strings(a)
return ReverseStringSlice(a)
} }
func ReverseStringSlice(array []string) []string {
length := len(array)
result := make([]string, length)
for i, elem := range array {
result[length-1-i] = elem
}
return result
}
// flattenAndMergeMap recursively flattens the given map into a map[string]bool // flattenAndMergeMap recursively flattens the given map into a map[string]bool
// of key paths (used as a set, easier to manipulate than a []string): // of key paths (used as a set, easier to manipulate than a []string):
// - each path is merged into a single key string, delimited with v.keyDelim (= ".") // - each path is merged into a single key string, delimited with v.keyDelim (= ".")