Conversation
|
Big thanks for this PR, it is very similar to what I imagined. |
|
@julienschmidt do you plan to merge soon? In general it might be useful to define an interface (I do that in my project): Then both the Router and RouteGroup could implement it. So it could be easily passed to modules to register it's handlers. |
Integrate and adapt julienschmidt/httprouter#89
Integrate and adapt julienschmidt/httprouter#89
Integrate and adapt julienschmidt/httprouter#89
|
No worries, something like that is definitely coming. However, I'd like to keep the package as simple as possible. My current idea is to make every route essentially a subrouter, i.e. every route registration returns a handle (containing just the path as a prefix) which can be used to register subroutes. It would also further encourage hierarchical URL design. I'm currently working on the last few projects for this term at university, afterwards I will finally bring this package up to date. |
|
@julienschmidt hi there! This is an awesome framework, and I just wanna check on the status of this pr-- it'd be a real nice addition. |
|
Such a clean implementation, any update? |
|
Hey, any news on this? 😊 @dbudworth can you rebase to |
|
Would love this to happen! 👍🏻 |
|
I would love to see a sub router feature. However as I see it being implemented, it wouldn't be helpful to me. Use cases that I come across are adding an http.Handler into my httprouter api. That http.Handler will have it's own set of routes defined. |
RouteGroup is a simple route mapper that delegates to an underlying Router instance when mapping paths and takes no part in handling of requests resulting in zero added per-request cost. Implemented as a simple struct to keep in the spirit of httprouter's design. Potential improvement being to create an interface for the common functions of Router and RouteGroup.
8d90774 to
1d4a653
Compare
|
Apologies, I just realized that I was asked to rebase this PR, quite some time ago. Just did, in case there's still interest in adding the RouteGroup feature. One annoying thing, vscode decided the comments in @halorium there isn't really a way to interrogate an http.Handler (interface) to get the list of paths it has mapped. That would work, but it takes on the cost of "double routing", in a sense. But I think that if you are already delegating functionality to a third party library that is likely not using as efficient of a routing system, then the cost will be negligible |
* Add contributing docs Signed-off-by: Lucas Santos <hello@lsantos.dev> * Add README Signed-off-by: Lucas Santos <lhs.santoss@gmail.com> * Add magefiles Signed-off-by: Lucas Santos <lhs.santoss@gmail.com>
|
What is the current situation with this PR? |
Note: This is similar to closed / rejected issue #57. The difference here is that the RouteGroup imposes no request overhead as it's only a proxy to the Router.METHOD() functions that prefixes the path.
Not sure if you are interested in this being in the standard httprouter library, it could easily be a stand alone add-on. Submitting it just in case you think it will be generally useful.
-- commit message --
RouteGroup is a simple route mapper that delegates to an underlying Router
instance when mapping paths and takes no part in handling of requests
resulting in zero added per-request cost.
Implemented as a simple struct to keep in the spirit of httprouter's design.
Potential improvement being to create an interface for the common functions of
Router and RouteGroup.