From 2c5b06a1e870f46f90583ba5561351b0036cb38e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20C=2E=20For=C3=A9s?= Date: Tue, 26 Nov 2024 20:54:26 +0100 Subject: [PATCH] fix(router): fixes middleware order --- problem.go | 2 ++ router.go | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/problem.go b/problem.go index 779d3c6..5b7437d 100644 --- a/problem.go +++ b/problem.go @@ -104,6 +104,8 @@ type Problem struct { Instance string } +// ProblemControlsResolver is a func that resolves to a response T given +// a [Problem] and a [http.Request]. type ProblemControlsResolver[R any] func(problem Problem, request *http.Request) R type ProblemControls struct { diff --git a/router.go b/router.go index 1137ab8..70cd079 100644 --- a/router.go +++ b/router.go @@ -109,8 +109,8 @@ func (router *Router) mux() *http.ServeMux { // the same as first calling the router middlewares and then the // provided [http.Handler]. func (router *Router) wrap(handler http.Handler) http.Handler { - for _, middleware := range router.middlewares { - handler = middleware(handler) + for i := len(router.middlewares) - 1; i >= 0; i-- { + handler = router.middlewares[i](handler) } return handler