Skip to content

chi.Walk no longer sees routes with custom HTTP methods #1021

Description

@cixel

In v5.2.3, chi.Walk no longer visits routes with custom HTTP methods. For example:

package main

import (
	"fmt"
	"net/http"

	"github.com/go-chi/chi/v5"
)

func main() {
	r := chi.NewMux()

	chi.RegisterMethod("QUACK")
	r.MethodFunc("QUACK", "/quack", func(w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(http.StatusOK)
	})

	chi.Walk(r, func(method string, route string, handler http.Handler, _ ...func(http.Handler) http.Handler) error {
		fmt.Println(method, route)
		return nil
	})
}

I believe the change responsible for this is 9b9fb55, which changed method name lookup to use reverseMethodMap instead of a utility function which iterated methodMap. As far as I can tell, the problem is that reverseMethodMap is not updated by RegisterMethod, so the lookup fails and the route is not added.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions