临时提交

This commit is contained in:
Liujian
2021-11-05 11:50:53 +08:00
parent 883a8a8d43
commit 0f32c1d19f
3 changed files with 67 additions and 38 deletions

View File

@@ -19,7 +19,11 @@ type IRouter interface {
SetRouter(id string, config *Config) error
Count() int
Del(id string) int
Handler() fasthttp.RequestHandler
Handler(ctx *fasthttp.RequestCtx)
}
type IRouterFilter interface {
DoFilter(ctx *http_context.Context) (isContinue bool, err error)
}
//Router 实现了路由树接口
@@ -28,6 +32,7 @@ type Router struct {
data eosc.IUntyped
match IMatcher
handler fasthttp.RequestHandler
chain []IRouterFilter
}
//NewRouter 新建路由树
@@ -45,22 +50,25 @@ func (r *Router) Count() int {
}
//Handler 路由树的handler方法
func (r *Router) Handler() fasthttp.RequestHandler {
return func(requestCtx *fasthttp.RequestCtx) {
match := r.match
if match == nil {
requestCtx.NotFound()
return
}
log.Debug("router handler", requestCtx.Request.String())
ctx := http_context.NewContext(requestCtx)
h, e, has := match.Match(ctx.Request())
if !has {
requestCtx.NotFound()
return
}
h.Handle(ctx, NewEndPoint(e))
func (r *Router) Handler(requestCtx *fasthttp.RequestCtx) {
match := r.match
if r.match == nil {
requestCtx.NotFound()
return
}
log.Debug("router handler", requestCtx.Request.String())
ctx := http_context.NewContext(requestCtx)
// TODO: 执行全局的Filter
h, e, has := match.Match(ctx.Request())
if !has {
requestCtx.NotFound()
return
}
h.Handle(ctx, NewEndPoint(e))
for _, c := range r.chain {
}
}
//SetRouter 将路由配置加入到路由树中