golang code
r := gin.New()
r.Use(func(ctx *gin.Context) {
fmt.Println(1)
// ctx.Next() Must be called to execute the next step
})
r.Use(func(ctx *gin.Context) {
fmt.Println(2)
})
r.GET("/test", func(ctx *gin.Context) {
ctx.String(http.StatusOK, "hello world")
})
r.Run("127.0.0.1:2020")
result
[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
- using env: export GIN_MODE=release
- using code: gin.SetMode(gin.ReleaseMode)
[GIN-debug] GET /test --> main.main.func3 (3 handlers)
[GIN-debug] [WARNING] You trusted all proxies, this is NOT safe. We recommend you to set a value.
Please check https://pkg.go.dev/github.com/gin-gonic/gin#readme-don-t-trust-all-proxies for details.
[GIN-debug] Listening and serving HTTP on 127.0.0.1:2020
1
2
question?
Why do we need to call Abort instead of interrupting without calling Next
Comment From: r0ld3x
So you want sequential
First it will first callback function which is fmt.Println(1)
and then fmt.Println(2)
?