Skip to content
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

Not all middlewares are present in chi.Walk #931

Open
dils2k opened this issue Jul 10, 2024 · 2 comments
Open

Not all middlewares are present in chi.Walk #931

dils2k opened this issue Jul 10, 2024 · 2 comments
Assignees

Comments

@dils2k
Copy link

dils2k commented Jul 10, 2024

Consider this example:

mux := chi.NewMux()
mux.With(middleware).Group(func(r chi.Router) {
	r.Route("/foo", func(r chi.Router) {
		r.With(middleware).Post("/bar", func(w http.ResponseWriter, r *http.Request) {})
	})
})

/foo/bar route is expected to have two middlewares: one inherited from the group, second defined for the route itself.

But when I use chi.Walk function to get all routes with corresponding middlewares /foo/bar route has only one middleware:

chi.Walk(mux, func(method, route string, handler http.Handler, middlewares ...func(http.Handler) http.Handler) error {
	fmt.Println(middlewares) // it prints [0x1047fcba0], array with only one element, but we expected two elements
	return nil
})
@VojtechVitek
Copy link
Contributor

Interesting, thank you. Mind investigating further, @dils2k?

@dils2k
Copy link
Author

dils2k commented Sep 18, 2024

Interesting, thank you. Mind investigating further, @dils2k?

yup, will try my best

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants