1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-22 20:30:55 +00:00
Beego/filter.go

37 lines
565 B
Go
Raw Normal View History

2013-09-09 16:00:11 +00:00
package beego
import (
"regexp"
)
type FilterRouter struct {
pattern string
regex *regexp.Regexp
filterFunc FilterFunc
hasregex bool
}
func (mr *FilterRouter) ValidRouter(router string) bool {
if mr.pattern == "" {
return true
}
2013-09-19 15:14:47 +00:00
if mr.pattern == "*" {
return true
}
2013-09-09 16:00:11 +00:00
if router == mr.pattern {
return true
}
if mr.hasregex {
if mr.regex.MatchString(router) {
return true
}
matches := mr.regex.FindStringSubmatch(router)
2013-10-12 08:56:30 +00:00
if len(matches) > 0 {
if len(matches[0]) == len(router) {
return true
}
2013-09-09 16:00:11 +00:00
}
}
return false
}