mirror of
				https://github.com/eolinker/apinto
				synced 2025-11-01 04:22:40 +08:00 
			
		
		
		
	临时提交
This commit is contained in:
		| @@ -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 将路由配置加入到路由树中 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Liujian
					Liujian