Comments (6)
I'd be happy to provide a PR if necessary.
from chi.
👍
from chi.
Hey @GeertJohan - a shorthand would be nice, but it would only save a bit of typing.. as so..
func NewSomethingCtx(stuff *Stuff) chi.Middleware {
return chi.Middleware(func(next chi.Handler) chi.Handler {
// stuff can be used here to set something up (should be done once, as mentioned in #10).
return chi.HandlerFunc(func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
// stuff can also be used here, on each request.
// actual middleware.
})
})
}
Im not convinced thats much better. Do you see another way? if so, it would be great to see a quick PR for the discussion.
from chi.
I liked it for documentation and readability. However, when trying to implement a quick example I found that it gets messy real quick. Existing func(next chi.Handler) chi.Handler
must still need be supported and since router.Use(..)
accepts interface{}
there can't be any type conversion going on during the call, which means that internally both types must be handled. It's probably not worth the effort without unless doing a breaking change.
from chi.
Didn't mean to close, although this probably can be closed..?
from chi.
I'd like to keep the middleware signature as close to the standard http.Handler middlewares. I'm going to close this ticket, but if you find an elegant approach please submit a PR. Thanks for the feedback!
from chi.
Related Issues (20)
- Panic if rctx is nil HOT 1
- runtime: goroutine stack exceeds 1000000000-byte limit while serving HTTP HOT 2
- Undefined Route Request Leads to Infinite Loop in route matching HOT 6
- How to test if a request path matches the pattern using chi router HOT 1
- chi.RouteContext(r.Context()).RoutePattern() returns ""
- Mount isn't compositing the route patterns HOT 1
- Unexpected Group behaviour HOT 1
- Can we log panics in one line? HOT 1
- log/slog's LogAttrs (and other methods) now requires a context as their first argument HOT 3
- Brotli compression not working
- Feature: Expose Context.methodsAllowed for use by MethodNotAllowedHandler
- Feature: on Go 1.22, fill `(*http.Request).PathValue` with URLParam data HOT 5
- Incorrect Route Matching Comment in chi.go
- [Doubt] Do you support i18n? HOT 4
- Possible bug can lead to security issue HOT 4
- URL params are not available inside middleware on the root router HOT 3
- Is jwtauth to validate jwt ? or can I create new jwt tokens using jwtauth? HOT 1
- Feature: on Go 1.22 pattern can start with an optional HTTP Method HOT 5
- bug: HandlerFunc does not support HTTP methods in patterns like #897
- Huma not respecting API Gateway path? HOT 1
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 chi.