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

Does gin.Recovery() run before or after Group middleware? #3870

Open
jimydavis opened this issue Mar 6, 2024 · 1 comment
Open

Does gin.Recovery() run before or after Group middleware? #3870

jimydavis opened this issue Mar 6, 2024 · 1 comment

Comments

@jimydavis
Copy link

jimydavis commented Mar 6, 2024

Which one of the following is more correct if I want to make sure Recovery is always run at the end?

From the way I understand the docs + other issues, it feels like global middleware is run as a priority BEFORE group level middleware.

Thank you for the help!

Global Recovery

r := gin.New()
r.Use(GetLoggerMiddleware())
r.Use(gin.Recovery())
groupAuthed := r.Group("", GetAuthMiddleware())
groupPublic := r.Group("")

Group Level Recovery

r := gin.New()
r.Use(GetLoggerMiddleware())
groupAuthed := r.Group("", GetAuthMiddleware(), gin.Recovery())
groupPublic := r.Group("", gin.Recovery())
@Sivaram151
Copy link

Sivaram151 commented Mar 6, 2024

Hi @jimydavis ,
If you want make sure regarding recovery middleware always runs at the end,
You can use the first approach (gin. Recovery() as the Global middleware of your router)
I think this is the only way to handle any panic across the routers

Hope this is okay :)

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