-
-
Notifications
You must be signed in to change notification settings - Fork 125
Gin compatibility layer per route middlewares #534
Description
Problem
As stated in #241 gin compatibility layer currently does not support per route middlewares. option.Middleware applies no middlewares to gin engine.
Points of interest
- Apply http middlewares (default ones for fuego
func (http.Handler) http.Handler) to gin engine using wrapping (easy task) - Apply gin middlewares to gin engine (
func (c gin.Context)) (bit harder, description below) - Global middlewares for gin? (very hard, have no ideas currently)
Solution
We don't introduce any API breaking changes, still store middlewares everywhere as func (http.Handler) http.Handler and convert them to gin ones when registering routes. Major problem is wrapping. Convert http middleware to gin is not a problem. But we also want to pass gin middlewares and it's a problem since we store all middlewares as http ones. So we have to convert one gin middleware twice. One when we pass it to storage using option, second when we apply it to gin. So idk if this way is reasonable cause converting gin middleware to http one is a bit runtime-consuming