You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using router groups, .Use does not do anything as middleware needs to be defined before routes. That is fine for global middleware, but doesn't work for groups which is not intention revealing and blocks essential patterns, such as different CORS middleware per group.
gin.RouterGroup does not expose the native http.Handler in order to pass it to third-party middleware libraries.
Problem
.Usedoes not do anything as middleware needs to be defined before routes. That is fine for global middleware, but doesn't work for groups which is not intention revealing and blocks essential patterns, such as different CORS middleware per group.gin.RouterGroupdoes not expose the nativehttp.Handlerin order to pass it to third-party middleware libraries.Consider this example:
It gets worse when you'd like to use third-party middleware which expects a
http.Handler. It would be great if this works:Instead I have to extract the code from the library into my own project, and if I only want it to apply to a group, we get something like this:
Solution
http.Handleringin.RouterGroup.Useto be used inside groupsI'm willing to contribute these changes if we agree on this and I get some tips on how to approach it.