Skip to content

Commit d5b89d5

Browse files
ralphocdolsvilenmarkov
authored andcommitted
added unique to filter arrays with unique items in custom-api
1 parent 97f43f8 commit d5b89d5

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

internal/glance/widget-custom-api.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,18 @@ var customAPITemplateFuncs = func() template.FuncMap {
543543
"concat": func(items ...string) string {
544544
return strings.Join(items, "")
545545
},
546+
"unique": func(key string, results []decoratedGJSONResult) []decoratedGJSONResult {
547+
seen := make(map[string]struct{})
548+
out := make([]decoratedGJSONResult, 0, len(results))
549+
for _, result := range results {
550+
val := result.String(key)
551+
if _, ok := seen[val]; !ok {
552+
seen[val] = struct{}{}
553+
out = append(out, result)
554+
}
555+
}
556+
return out
557+
},
546558
}
547559

548560
for key, value := range globalTemplateFunctions {

0 commit comments

Comments
 (0)