Skip to content

chi.Walk missing middlewares #750

Description

@ebabani

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:

	r := chi.NewRouter()

	r.Use(middleware.RequestID)

	r.Get("/A", func(w http.ResponseWriter, r *http.Request) {})

	r.Group(func(r chi.Router) {
		r.Use(middleware.Timeout(2500 * time.Millisecond))

		r.Get("/B", func(w http.ResponseWriter, r *http.Request) {})

		r.Route("/C", func(r chi.Router) {

			// Walk on the below route does not show the Timeout middleware
			r.Get("/D", func(w http.ResponseWriter, r *http.Request) {})
		})
	})

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions