From df391f09d6109b8fba55877730c62fbc4455b67d Mon Sep 17 00:00:00 2001 From: Muhammad Azzahid Date: Mon, 4 Nov 2024 01:06:48 +0700 Subject: [PATCH] fix: first added middleware should be executed first --- message/router.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/message/router.go b/message/router.go index 0ecf48c6d..28fffe42a 100644 --- a/message/router.go +++ b/message/router.go @@ -622,7 +622,7 @@ func (h *handler) run(ctx context.Context, middlewares []middleware) { middlewareHandler := h.handlerFunc // first added middlewares should be executed first (so should be at the top of call stack) - for i := len(middlewares) - 1; i >= 0; i-- { + for i := 0; i < len(middlewares); i++ { currentMiddleware := middlewares[i] isValidHandlerLevelMiddleware := currentMiddleware.HandlerName == h.name if currentMiddleware.IsRouterLevel || isValidHandlerLevelMiddleware {