[Proposal] Use gorilla/mux router V2 #204
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR shows how much the SimpleServer would get cleaned up if we used gorilla/mux as the main router.
Background:
The SimpleServer has only one Router: gorilla/mux. However, there's a lot of abstraction built around it that limits its features. Such missing features are 1. Multiple Prefixes, 2. Group Middlewares, 3. Trailing Slashes, and more.
Evolution
With server/kit being the 2nd generation of Gizmo, we should make the SimpleServer be truly simple without losing any of the production-default features that it has provided in the past, this PR achieves that.
Notable changes:
Prefix
and one globalMiddleware
. Therefore, you can use gorilla/mux features to have multiple Sub Routers with varying prefixes, and apply Middlewares to groups of routes together (not just one for each handler, or global ones only)Which makes the SimpleServer a lot quicker to learn, spin up, and work with.
TODO:
Further design considerations:
It'd be nice to make
server.Run
take an http.Handler, this way Register has one job (not two) and Run can take Handler-compositions.If we want to be more flexible and have the user pick a mux, we can make Register take a "registerer" function or interface that will register all the routes regardless of what the mux is.