add support for subtree routing#57
Conversation
|
Excellent. A readMe "sub-routers use case" (complement to the test) would be useful. If have I time I will document one. Not sure when. |
|
Sorry, but this is not going to be merged since it basically breaks the main promises of this router. But I agree, something like sub-routers are feasible. My current plan is to simple return a handle ("sub-router") when registering a route which can be named (#10) and used for registering sub-routes. |
|
Since the idea in general is great and you seems like you put some effort in it (thanks for that!) let me explain a bit further why I don't want to merge this implementation: HttpRouter is intended as a lightweight and slim package. This also includes package API, which should be as simple as possible. Therefore, this router will also never be as powerful as gorilla/mux for example. I think this approach is problematic because it requires manual chaining of the routers, introduces another rather confusing public method and actually slows down the router. It is convenient to use sub-routers, but the more you use it, the more overhead you introduce. |
|
Thanks for your helpful response. I'll try to explain why I think that this is The scenario I have in mind is this one: suppose I am writing a package The net/http/pprof package is a nice example of this (except that it The package might look something like this: I would like to embed a handler created with A way around this, which I think is compatible with the solution but this isn't nearly as nice. It precludes the package from adding its own The nice thing about having a Handle is that it's composable. It As for performance, yes, there is a performance hit of around Here's a comparative benchmark: There will of course be some performance overhead from using embedded routers As for the new public method, I agree that the name is not ideal, but is |
This makes it feasible to compose routers modularly from
sub-routers that implement independent subtrees, rather
than requiring all routes to be combined into a single
large router.