Comments (7)
yes, i am using it in my project and besides that i believe native implementation should be default one always available. So in our case net/http should always come before fasthttp
from gorouter.
Give me some time, need to think about a proper solution for it. For now we could increase test coverage, and maybe remove duplication for logic between routers ?
Right now we have every case done twice for each router.
from gorouter.
Not to worry better have issues open for extended periods rather than rushing to close them before all implications are fully investigated.
What do you mean by
remove duplication for logic between routers
Between the net/http
and fasthttp
?
I thought the idea to maintain both was for compatibility reasons since gorouter is a wrapper around them.
from gorouter.
I mean we have same test logic repeated for each implementation of a router, what we should have is one function where you inject router or something like that
from gorouter.
Do we really want to maintain net/http
implementation at all since it's way slower for most operations ?
from gorouter.
@mar1n3r0 have a look here 532090c
I split Node
interface into two interfaces RouteAware
and MiddlewareAware
. Still having one Tree
and Node
types. Router now has two trees one for routes and one for middleware. Route one is sorted by WithRoute
method where middleware is not (this solves our issue). Later on when matching path to tree I match separately path against each tree. Most of the tests are failing now because interface has been changed. Most likely there are going to be some bugs but to find them we need to update tests.
Please give it a deep thoughts, if you can see any potential problems now or in the feature with that solution/implementation.
from gorouter.
Amended the tests a tad just to demonstrate that the problem remains: 1cc5ab9
Later on when matching path to tree I match separately path against each tree.
The thing is it's the same tree which is already ordered with static node priority. I think this is a step in the right direction and proves that this can not be solved without a second tree with custom ordering based on middleware index.
It is easier for me to visualize it with layers as an onion like structure. RouteAware nodes are only meant as a gateway and serve no other purpose. So this original RouteTree is used only to validate that the middleware is actually compliant with the registered routes and can start generating its own MiddlewareTree ordered by its own index.
We can take some of the notes from httprouter for the research as gorouter seems to share the same structure: only explicit matches
The limitations of using a single tree with wildcards:
Only explicit matches: With other routers, like http.ServeMux, a requested URL path could match multiple patterns. Therefore they have some awkward pattern priority rules, like longest match or first registered, first matched. By design of this router, a request can only match exactly one or no route. As a result, there are also no unintended matches, which makes it great for SEO and improves the user experience.
Note: Since this router has only explicit matches, you can not register static routes and parameters for the same path segment. For example you can not register the patterns /user/new and /user/:user for the same request method at the same time. The routing of different request methods is independent from each other.
from gorouter.
Related Issues (11)
- Performance Upgrades HOT 1
- Wildcard node matching HOT 1
- Refactor tests HOT 6
- Add more test case
- Incompatible tag in go.mod HOT 4
- Static path middleware is applied to all wildcard paths HOT 12
- Fix Wiki small code example typos HOT 1
- Context params missing HOT 1
- typo in project description HOT 1
- When to prefer gorouter over httprouter HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gorouter.