New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inconsistent Chi(net/http) middleware func signature #286
Comments
Hey @wangyoucao577 That sounds like a perfectly reasonable idea; in fact after using the existing signature for a bit, I agree that it is a bit unfortunate 😅 Now the only problem that arises is that we'd be possibly breaking someone's code. But:
Let's ask for the opinion of the main maintainer @deepmap-marcinr ? |
@maclav3 Excellent! Personally I agree with you that the impact should be small, maybe we don't need to be so that strict, just make the changes fastly. |
I'm happy with this change, however, it breaks people's code when they re-generate after such an update. I've been super busy with my main job and haven't had time to fix this properly, but my plan is to create a separate versioning dimension to allow us to fix such code generation issues, and allow people to pick the version of templates to use, eg, I'm still thinking about how to do it properly, because it can be a maintenance nightmare. I'd also like to make it easier to support more routers, like Gin |
Hi, is this still on track? Best Greetings |
Hi there,
Many thanks to @maclav3 , I'm able to use the chi middlewares per handler(PR #259) with the request validator chi-middleware (PR #278) to validate restful request via openapi spec. However, I found that the middleware func interface is inconsistent.
oapi-codegen
generated middleware func singnature istype MiddlewareFunc func(http.HandlerFunc) http.HandlerFunc
, but most of industry guys usefunc(http.Handler) http.Handler
instead(e.g., https://www.alexedwards.net/blog/making-and-using-middleware). PR #278 satisfiedfunc(http.Handler) http.Handler
as well.As above, I have to write some ugly codes like this to make them work:
So I'll suggest to change the MiddlewareFunc singature to
type MiddlewareFunc func(http.Handler) http.Handler
when generate code.@maclav3 How's your opinion?
Thanks!
The text was updated successfully, but these errors were encountered: