Files
apinto/router-http/plan-one.go
黄孟柱 a10d4b53a0 init
2021-07-20 11:11:39 +08:00

34 lines
622 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package router_http
import (
"github.com/eolinker/goku-eosc/router"
"net/http"
)
type Checker_One interface {
check(v string) bool
}
// 适合从request检测单个值的类型如host、location
type _Plan_One struct {
reader Reader
checkers []Checker_One
nexts []router.IRouterHandler
}
func (p *_Plan_One) Match(request *http.Request) (string, bool) {
v := p.reader.read(request)
for i, c := range p.checkers {
if c.check(v) {
res, has := p.nexts[i].Match(request)
// 防止错失后面可能匹配成功的路径
if !has {
continue
}
return res, has
}
}
return "", false
}