-
Notifications
You must be signed in to change notification settings - Fork 14
/
multi.go
47 lines (37 loc) · 1.03 KB
/
multi.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright 2012 The Gorilla Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package reverse
import (
"net/http"
)
// All ------------------------------------------------------------------------
// NewAll returns a group of matchers that succeeds only if all of them match.
func NewAll(matchers []Matcher) All {
return All(matchers)
}
// All is a set of matchers, and all of them must match.
type All []Matcher
func (m All) Match(r *http.Request) bool {
for _, v := range m {
if !v.Match(r) {
return false
}
}
return true
}
// One ------------------------------------------------------------------------
// NewOne returns a group of matchers that succeeds if one of them matches.
func NewOne(matchers []Matcher) One {
return One(matchers)
}
// One is a set of matchers, and at least one of them must match.
type One []Matcher
func (m One) Match(r *http.Request) bool {
for _, v := range m {
if v.Match(r) {
return true
}
}
return false
}