cleanup of addRoute
This commit is contained in:
parent
ce036f428d
commit
53732c24e5
|
@ -63,22 +63,25 @@ func (r *Router) Use(middleware ContextFunc) {
|
||||||
|
|
||||||
func (router *Router) addRoute(method, path string, target ContextFunc) {
|
func (router *Router) addRoute(method, path string, target ContextFunc) {
|
||||||
router.router.Handle(
|
router.router.Handle(
|
||||||
method,
|
method,
|
||||||
router.path + path,
|
router.path + path,
|
||||||
func(response http.ResponseWriter,
|
router.createHandleFunction(target),
|
||||||
request *http.Request,
|
)
|
||||||
params httprouter.Params) {
|
}
|
||||||
|
|
||||||
|
func (r *Router) createHandleFunction(target ContextFunc) httprouter.Handle {
|
||||||
|
return func(
|
||||||
|
response http.ResponseWriter,
|
||||||
|
request *http.Request,
|
||||||
|
params httprouter.Params) {
|
||||||
|
|
||||||
ctx := &Context{
|
ctx := &Context{
|
||||||
request,
|
request, response, params, addToFuncList(r.funcList, target), 0,
|
||||||
response,
|
|
||||||
params,
|
|
||||||
addToFuncList(router.funcList, target),
|
|
||||||
0,
|
|
||||||
}
|
}
|
||||||
for i := 0; i < len(ctx.funcList); i++ {
|
for i := 0; i < len(ctx.funcList); i++ {
|
||||||
ctx.funcList[i](ctx)
|
ctx.funcList[i](ctx)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Router) Start() {
|
func (r *Router) Start() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user