From dd65a8d04bcbdb92d0284e37b560aa430e2273d4 Mon Sep 17 00:00:00 2001 From: yusing Date: Mon, 5 May 2025 13:36:08 +0800 Subject: [PATCH] style: replace for loops with slices.Contains --- internal/route/rules/on.go | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/internal/route/rules/on.go b/internal/route/rules/on.go index 8c9e29f..8972fa9 100644 --- a/internal/route/rules/on.go +++ b/internal/route/rules/on.go @@ -3,6 +3,8 @@ package rules import ( "net/http" + "slices" + "github.com/yusing/go-proxy/internal/gperr" "github.com/yusing/go-proxy/internal/net/types" "github.com/yusing/go-proxy/internal/utils/strutils" @@ -47,12 +49,7 @@ var checkers = map[string]struct { } } return func(cached Cache, r *http.Request) bool { - for _, vv := range r.Header[k] { - if v == vv { - return true - } - } - return false + return slices.Contains(r.Header[k], v) } }, }, @@ -74,12 +71,7 @@ var checkers = map[string]struct { } return func(cached Cache, r *http.Request) bool { queries := cached.GetQueries(r)[k] - for _, query := range queries { - if query == v { - return true - } - } - return false + return slices.Contains(queries, v) } }, },