Comments (6)
Hi, fastroute is built with minimal code to support url parameters and compose the routes, it basically can replace any http router with some customizations.
If you need extreme efficiency for context like parameters. You may copy the code and modify it so that you can add your own parameters instead just having path based parameters carried in request.
It depends on an use case, but using standar go context might be as well a reasonable decision, since it supports the deadline and cancellation.
from fastroute.
Thanks for the response.
I was thinking about modifying the parameters to allow for adding a custom one, but then I want to keep the distinction between path params, and middleware injected context values.
If I were to go the native context path:
func aMiddleware(routes ...fastroute.Router) fastroute.Router {
return fastroute.RouterFunc(func(req *http.Request) http.Handler {
for _, r := range routes {
if h := r.Route(req); h != nil {
ctx := req.Context()
context.WithValue(ctx, "gateway", "myvalue")
<req = req.WithContext(ctx)... ?>
return h
}
}
})
}
Also something like:
fastroute.New("/:id/*", handler)
Does not seem to work. Is that a defect?
from fastroute.
it works as expected, you just need an argument name /:id/*rest
would match
/1/anything
to params["id": "1", "rest": "/anything"]
/1/path/to/something
to params["id": "1", "rest": "/path/to/something"]
from fastroute.
Figured after going through the code. Thanks for the quick response. Would be nice to add an example for that case.
from fastroute.
There are enough examples for path matching in godoc package description, probably you haven't read it all
from fastroute.
Thanks.
Yes. I never looked at these docs. Was going through the readme and code.
I am thinking of adding a logger with latency per request.
from fastroute.
Related Issues (5)
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 fastroute.