From 2a612eb82faeea8c0d499cdde0abf54398bb39d0 Mon Sep 17 00:00:00 2001 From: NiseVoid Date: Wed, 3 Jul 2019 12:26:29 +0200 Subject: [PATCH] Fix middlewares getting overwritten --- router.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/router.go b/router.go index 584ba01..1584600 100644 --- a/router.go +++ b/router.go @@ -136,7 +136,11 @@ func (r *Router) getHttpr() *httprouter.Router { 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) {