Files
QSfera/vendor/github.com/samber/slog-common/finder.go
T
2025-11-20 14:58:30 +01:00

28 lines
584 B
Go

package slogcommon
import "log/slog"
func FindAttrByKey(attrs []slog.Attr, key string) (slog.Attr, bool) {
for i := range attrs {
if attrs[i].Key == key {
return attrs[i], true
}
}
return slog.Attr{}, false
}
func FindAttrByGroupAndKey(attrs []slog.Attr, groups []string, key string) (slog.Attr, bool) {
if len(groups) == 0 {
return FindAttrByKey(attrs, key)
}
for i := range attrs {
if attrs[i].Key == key && attrs[i].Value.Kind() == slog.KindGroup {
return FindAttrByGroupAndKey(attrs[i].Value.Group(), groups[1:], key)
}
}
return slog.Attr{}, false
}