Fix middlewares getting overwritten

This commit is contained in:
Nise Void 2019-07-03 12:26:29 +02:00
parent 317961ab6e
commit 2a612eb82f
Signed by: NiseVoid
GPG Key ID: FBA14AC83EA602F3

View File

@ -136,7 +136,11 @@ func (r *Router) getHttpr() *httprouter.Router {
handle = handlePOST(r, v.Handle) handle = handlePOST(r, v.Handle)
} }
httpr.Handle(v.Method, v.Path, handleReq(r, handle, append(r.middleware, v.Middleware...))) middleware := make([]Middleware, len(r.middleware)+len(v.Middleware))
copy(middleware, r.middleware)
copy(middleware[len(r.middleware):], v.Middleware)
httpr.Handle(v.Method, v.Path, handleReq(r, handle, middleware))
} }
httpr.NotFound = http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { httpr.NotFound = http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {