julienschmidt / httprouter

A high performance HTTP request router that scales well
https://pkg.go.dev/github.com/julienschmidt/httprouter
BSD 3-Clause "New" or "Revised" License
16.63k stars 1.47k forks source link

Plan to Consolidate with net/http @ 1.22? #380

Open garukun opened 8 months ago

garukun commented 8 months ago

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!

bradleypeabody commented 3 months ago

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?