|
6 | 6 | "net" |
7 | 7 | "net/http" |
8 | 8 | "regexp" |
| 9 | + "slices" |
9 | 10 | "strings" |
10 | 11 |
|
11 | 12 | "github.com/fox-toolkit/fox/internal/netutil" |
@@ -59,12 +60,7 @@ func (m QueryMatcher) Match(c RequestContext) bool { |
59 | 60 | if len(values) == 0 { |
60 | 61 | return false |
61 | 62 | } |
62 | | - for _, v := range values { |
63 | | - if v == m.value { |
64 | | - return true |
65 | | - } |
66 | | - } |
67 | | - return false |
| 63 | + return slices.Contains(values, m.value) |
68 | 64 | } |
69 | 65 |
|
70 | 66 | // Equal reports whether matcher is a [QueryMatcher] with the same key and value. |
@@ -129,12 +125,7 @@ func (m QueryRegexpMatcher) Match(c RequestContext) bool { |
129 | 125 | if len(values) == 0 { |
130 | 126 | return false |
131 | 127 | } |
132 | | - for _, v := range values { |
133 | | - if m.regex.MatchString(v) { |
134 | | - return true |
135 | | - } |
136 | | - } |
137 | | - return false |
| 128 | + return slices.ContainsFunc(values, m.regex.MatchString) |
138 | 129 | } |
139 | 130 |
|
140 | 131 | // Equal reports whether matcher is a [QueryRegexpMatcher] with the same key and regular expression source. |
@@ -182,12 +173,7 @@ func (m HeaderMatcher) Match(c RequestContext) bool { |
182 | 173 | if len(values) == 0 { |
183 | 174 | return false |
184 | 175 | } |
185 | | - for _, v := range values { |
186 | | - if v == m.value { |
187 | | - return true |
188 | | - } |
189 | | - } |
190 | | - return false |
| 176 | + return slices.Contains(values, m.value) |
191 | 177 | } |
192 | 178 |
|
193 | 179 | // Equal reports whether matcher is a [HeaderMatcher] with the same key and value. |
@@ -247,12 +233,7 @@ func (m HeaderRegexpMatcher) Match(c RequestContext) bool { |
247 | 233 | if len(values) == 0 { |
248 | 234 | return false |
249 | 235 | } |
250 | | - for _, v := range values { |
251 | | - if m.regex.MatchString(v) { |
252 | | - return true |
253 | | - } |
254 | | - } |
255 | | - return false |
| 236 | + return slices.ContainsFunc(values, m.regex.MatchString) |
256 | 237 | } |
257 | 238 |
|
258 | 239 | // Equal reports whether matcher is a [HeaderRegexpMatcher] with the same key and regular expression source. |
|
0 commit comments