filter.go
592 Bytes
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
package beego
import (
"regexp"
)
type FilterRouter struct {
pattern string
regex *regexp.Regexp
filterFunc FilterFunc
hasregex bool
params map[int]string
}
func (mr *FilterRouter) ValidRouter(router string) bool {
if mr.pattern == "" {
return true
}
if mr.pattern == "*" {
return true
}
if router == mr.pattern {
return true
}
if mr.hasregex {
if mr.regex.MatchString(router) {
return true
}
matches := mr.regex.FindStringSubmatch(router)
if len(matches) > 0 {
if len(matches[0]) == len(router) {
return true
}
}
}
return false
}