mirror of
https://github.com/spf13/viper
synced 2025-05-05 19:57:18 +00:00
Sort keys returned by AllKeys in reverse order
This commit is contained in:
parent
d3bdf71242
commit
0b0114ad80
1 changed files with 13 additions and 1 deletions
14
viper.go
14
viper.go
|
@ -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 (= ".")
|
||||||
|
|
Loading…
Add table
Reference in a new issue