refactor: use slices.Contains to simplify code

Signed-off-by: tanhuaan <tanhuaan@outlook.com>
This commit is contained in:
tanhuaan
2025-07-30 16:32:57 +08:00
parent 1470afb715
commit 0e79c4bd2a
2 changed files with 4 additions and 12 deletions

View File

@@ -12,6 +12,7 @@ import (
"net/netip"
"os"
"regexp"
"slices"
"strconv"
"strings"
"sync"
@@ -49,12 +50,7 @@ func FileExists(filename string) bool {
// Contains returns true if needle is contained in haystack
func Contains[T comparable](haystack []T, needle T) bool {
for _, s := range haystack {
if s == needle {
return true
}
}
return false
return slices.Contains(haystack, needle)
}
// ContainsIP returns true if any one of the of prefixes contains the ip.