julienschmidt/httprouter

Plan to Consolidate with net/http @ 1.22?

garukun opened this issue · 1 comments

Go 1.22 has released Enhanced routing patterns; I wonder if there's been any thoughts phasing this library to be more compatible with stdlib, such as leveraging the http.Request object for the path params, or supporting the stdlib path param patterns, etc.

This router is already awesome. I think it would even greater if it can allow a stdlib ServeMux with path params to seamlessly transition to httprouter with a speed upgrade.

Thanks for the consideration!

I haven't looked too closely, but it seems like updating https://pkg.go.dev/github.com/julienschmidt/httprouter#Router.Handler and https://pkg.go.dev/github.com/julienschmidt/httprouter#Router.HandlerFunc to just call https://pkg.go.dev/net/http#Request.SetPathValue in addition to the existing behavior would be the primary thing that's needed (at least to make it so path params could be used with handlers and handler functions interchangeably with this library and http.ServeMux). It could be easily guarded in a separate file with a build tag to only do this in 1.22+, for backward compatibility.

I wonder if that change and updating the readme to mention it is all that is needed? If so that's a pretty simple update. @julienschmidt would you be open to a PR on this?