Gin adaptor middlewares#535
Conversation
|
So I decided to simplify task with such separation:
|
|
Is there not a way to convert |
|
ehhhh, i guess it does make sense that each adaptors community would want to use their adaptors. If someone wanted to use a fuego middleware wrapping themselves wouldn't be very difficult as pretty much every community has a func to wrap http.Handler... |
|
Really interested in what others think as well. |
Indeed there is some functions for conversion (but no function for such conversion. You can try it yourself in some playground). I explained it in issue more detailed but my English might be bad so... We have two types of middlewares:
Before this PR all middlewares was stored as
On the other hand, if you are ok that we store middlewares as |
|
To respond to
It is possible though. It's not prettiest thing. I was looking at how the adaptor from go-fiber does it: return func(c *gin.Context) {
handler := mw(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
c.Request = r
c.Writer = &ginResponseWriter{ResponseWriter: w, ginWriter: c.Writer}
c.Next()
}))
handler.ServeHTTP(c.Writer, c.Request)
}I believe we'd have to set reset the headers up as well. So this code isn't complete. The trade off here is that we would need to do this for every adaptor going forward. The larger concern that I have here is the other way. Converting gin middleware to Edit: Ope. Just read your second point. I see we're pretty aligned there. |
|
This kinda lends to my thought here as well: #394 (comment) Trying to dictate too much on how configure each adaptors routes/server would cripple this project. |
|
Was thinking about this some. Maybe we should wrap our BaseRoute with GinRoute |
Can you please provide some example? Can't understand the idea |
|
Right now a gin handler will return func GetGin(engine *fuego.Engine, ginRouter gin.IRouter, path string, handler gin.HandlerFunc, options ...func(*fuego.BaseRoute)) *fuego.Route[any, any, any] {
return handleGin(engine, ginRouter, http.MethodGet, path, handler, options...)
}*fuego.Route[any, any, any] My though is to wrap this like: type GinRoute[ResponseBody any, RequestBody any, Params any] struct {
Route[any, any, any]
middlewares []func(c *gin.Context)
}
// Route is the main struct for a route in Fuego.
// It contains the OpenAPI operation and other metadata.
// It is a wrapper around BaseRoute, with the addition of the response and request body types.
type Route[ResponseBody any, RequestBody any, Params any] struct {
BaseRoute
}Not really sure how much would need to change though tbh. It was just a passing thought on a Saturday morning so it will need to be investigated. |
|
Hm... I see no problem with options ...func(*fuego.BaseRoute)Main problem here is they are applied to func handleFuego[T, B, P any](engine *fuego.Engine, ginRouter gin.IRouter, method, path string, fuegoHandler func(c fuego.Context[B, P]) (T, error), options ...func(*fuego.BaseRoute)) *fuego.Route[T, B, P] {
baseRoute := fuego.NewBaseRoute(method, ginToFuegoRoute(path), fuegoHandler, engine, options...)
// ...
}We want to apply option to gin but we can apply it only to BaseRoute |
|
@dylanhitt @EwenQuim sorry, but I still can't understand your idea... It would be cool if you provide some draft/MRE so I can finish this PR |
|
@evilenzo any plans to make this work? |
Resolves #534 (more details there)