Skip to content
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

IRoutes.Use() behaves erratic when used after POST/GET/... #4109

Open
simon-winter opened this issue Dec 2, 2024 · 2 comments
Open

IRoutes.Use() behaves erratic when used after POST/GET/... #4109

simon-winter opened this issue Dec 2, 2024 · 2 comments

Comments

@simon-winter
Copy link

Description

When creating a IRoute with middleware like this

route := ginEngine.GET("/test", func(ctx *gin.Context) { /**/) })
route.Use( someHandlerFunc() )

the middleware doesn't trigger, or triggers when it shouldn't.

I register routes for a generic class, so that i have some default endpoints per type.
For some types i want to be able to modify these default endpoints and tried to do this via middleware.
When using Use() on IRoute or even RouterGroup objects, it breaks when being added after its respective ginengine.post calls.
They won't trigger at all, or trigger for the wrong route

Expectations

I can add HandlerFuncs to any IRoute at any time in the code and it gets executed before the handlerFunc provided by the ginEngine.POST/GET/... calls

Actual result

Registering Handler Funcs directly to the return value of ginEngine.POST/GET/... calls registers the Handler in some random handlers but not the desired Route

Environment

  • go version: 1.23.3
  • gin version (or commit ref): 1.10.0
  • operating system: Windows
@VarusHsu
Copy link

VarusHsu commented Dec 3, 2024

route.Use( someHandlerFunc() ) should before route := ginEngine.GET("/test", func(ctx *gin.Context) { /**/) })

@simon-winter
Copy link
Author

Yes, but this shouldn't be like that.
Router get handeld later, so order of registration should not Matter.
Also adding in Middleware after the handlers leads to undefined behavior which is also odd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants