-
-
Notifications
You must be signed in to change notification settings - Fork 983
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
chi.Walk missing middlewares #750
Comments
I guess the issue is that |
It does seem related to the |
Group() is used for inlining middleware, where as Rotue() mount a subrouter -- it's a subtle difference, but there is one. The middlewares however will be there along the C/D route. If I recall -- the inline middleware stack is computed and reduced in memory, and we don't keep around in memory the middleware stack, which is why we can't walk it. We could definitely add it, it just means a bit more code. It would be safe to keep, but would only be useful for walking like in this case. |
In terms of functionality all is good, it was just surprising behaviour when I hit this. For context, I am using the walk function to write tests agains the router we're using. I was writing checks to ensure certain endpoints were always behind an auth middleware. I'm not super familiars with the chi internals, but if you can point me in the general area I can take a look and create a PR. |
@ebabani what did you end up doing for testing with Route() and Group()? |
Hey @ganicus, We ended up not writing an explicit test for the middleware checks. We only have a handful of routes that don't have the auth middleware, and keeping that grouping separate from the main routing logic. The only route tests we have are to make sure our api routes match our documented routes. We use https:/swaggo/swag for our swagger docs, and our route tests confirm that all the chi routes exactly match the swagger declared routes. |
Hi,
I was trying to use chi.Walk to get a report of all routes and the middlewares used by every route. I noticed that some of the middlewares were missing from some of the nested routes when using groups.
Example routes:
In the example above, I expected the
C/D
route to have both RequestId and Timeout middlewares. but chi.Walk only shows RequestID.It's possible I'm missing something here and this is behaving as expected.
Go playground link: https://go.dev/play/p/HKh7cA35Bgx
The text was updated successfully, but these errors were encountered: