Upstream knadh/koanf state of the touched files before e3921078a3

This commit is contained in:
upstream committed 2026-09-04 08:08:58 +02:00
1 parent 219bbcd219
commit 15e76cb3d5
2 files changed
+21 -197

No files matched your search

+21 -28
View File
@@ -368,26 +368,29 @@ func (ko *Koanf) Get(path string) any {
return out
}
// Slices returns a list of Koanf instances constructed from the value
// at path. It accepts []map[string]any or []any containing map[string]any
// elements. Non-slice elements are skipped.
// Slices returns a list of Koanf instances constructed out of a
// []map[string]any interface at the given path.
func (ko *Koanf) Slices(path string) []*Koanf {
out := []*Koanf{}
if path == "" {
return out
}
switch v := ko.Get(path).(type) {
case []map[string]any:
for _, mp := range v {
out = ko.appendMap(mp, out)
}
case []any:
for _, item := range v {
if mp, ok := item.(map[string]any); ok {
out = ko.appendMap(mp, out)
}
// Does the path exist?
sl, ok := ko.Get(path).([]any)
if !ok {
return out
}
for _, s := range sl {
mp, ok := s.(map[string]any)
if !ok {
continue
}
k := New(ko.conf.Delim)
_ = k.merge(mp, new(options))
out = append(out, k)
}
return out
@@ -413,16 +416,13 @@ func (ko *Koanf) MapKeys(path string) []string {
return out
}
// A value set with Set() or by a Provider such as structs keeps its native
// map type, so the keys have to be read through reflection too.
rv := reflect.ValueOf(o)
if rv.Kind() != reflect.Map || rv.Type().Key().Kind() != reflect.String {
mp, ok := o.(map[string]any)
if !ok {
return out
}
out = make([]string, 0, rv.Len())
for _, k := range rv.MapKeys() {
out = append(out, k.String())
out = make([]string, 0, len(mp))
for k := range mp {
out = append(out, k)
}
sort.Strings(out)
return out
@@ -656,10 +656,3 @@ func textUnmarshalerHookFunc() mapstructure.DecodeHookFuncType {
return result, nil
}
}
// appendMap creates new Koanf instances from a map returns a slice of Koanf instances.
func (ko *Koanf) appendMap(mp map[string]any, out []*Koanf) []*Koanf {
k := New(ko.conf.Delim)
_ = k.merge(mp, new(options))
return append(out, k)
}