Skip to content

fix: access named variables in middlewares #438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

yokkkoso
Copy link
Contributor

I moved the execution of middlewares to the Handle of the matched route, and not before finding the routes, since otherwise it is impossible to access the pattern of the route, and accordingly to get named variables in this route. This allows access to e.Vars inside the middleware, as well as the ability to add middlewares for each specific route

@topi314
Copy link
Member

topi314 commented Mar 18, 2025

I am not a fan of introducing middlewares for each handler. This can already done using

r := handler.New()
r.With(middleware).SlashCommand("pattern", func...)

If you want multiple handlers to have a middleware just use a r.Group or r.Route

@yokkkoso yokkkoso changed the title chore: access named variables in middlewares and per-route middlewares fix: access named variables in middlewares Mar 18, 2025
@topi314
Copy link
Member

topi314 commented Mar 18, 2025

closing this since it's working as intended.
The handler package is inspired by go-chi where we execute middlewares as we traverse the router tree. Because of this not all variables are accessible directly

@topi314 topi314 closed this Mar 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants