Backend: Use slices.Contains to simplify code (#4975)

Signed-off-by: hardlydearly <799511800@qq.com>
This commit is contained in:
hardlydearly
2025-04-30 21:25:05 +08:00
committed by GitHub
parent bb67dca507
commit 060924c19a
2 changed files with 4 additions and 14 deletions

View File

@@ -2,6 +2,7 @@ package service
import (
"net/url"
"slices"
"strings"
)
@@ -40,13 +41,7 @@ func (h Heuristic) MatchDomain(match string) bool {
return true
}
for _, m := range h.Domains {
if m == match {
return true
}
}
return false
return slices.Contains(h.Domains, match)
}
func (h Heuristic) Discover(rawUrl, user string) *url.URL {

View File

@@ -2,6 +2,7 @@ package duf
import (
"fmt"
"slices"
"strings"
"github.com/IGLOU-EU/go-wildcard"
@@ -26,13 +27,7 @@ func parseCommaSeparatedValues(values string) FilterValues {
// validateGroups validates the parsed group maps.
func validateGroups(m FilterValues) error {
for k := range m {
found := false
for _, g := range groups {
if g == k {
found = true
break
}
}
found := slices.Contains(groups, k)
if !found {
return fmt.Errorf("unknown device group: %s", k)