Files
upstream-traggo/dashboard/entry/tagcheck.go
upstream-mirror cda7c1a474
Some checks failed
build / build (push) Failing after 3s
snapshot of https://github.com/traggo/server.git (master, 2026-09-16; blobs > 131072B omitted)
2026-09-16 05:24:45 +05:00

34 lines
722 B
Go

package entry
import (
"fmt"
"github.com/traggo/server/model"
)
func tagsDuplicates(tags []model.DashboardTagFilter) error {
existingTags := make(map[model.DashboardTagFilter]struct{})
for _, tag := range tags {
if _, ok := existingTags[tag]; ok {
tagType := "exclude"
if tag.Include {
tagType = "include"
}
return fmt.Errorf("%s tags: tag '%s' is present multiple times", tagType, tag.Key+":"+tag.StringValue)
} else {
copyTag := tag
copyTag.Include = !copyTag.Include
if _, ok := existingTags[copyTag]; ok {
return fmt.Errorf("tag '%s' is present in both exclude tags and include tags", tag.Key+":"+tag.StringValue)
}
}
existingTags[tag] = struct{}{}
}
return nil
}