We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
// TransactionMiddleware filter gin invocation // NOTE: when use gin,must set gin.ContextWithFallback true when gin version >= 1.8.1 func TransactionMiddleware() gin.HandlerFunc { return func(ctx *gin.Context) { xid := ctx.GetHeader(constant.XidKey) if xid == "" { xid = ctx.GetHeader(constant.XidKeyLowercase) }
if len(xid) == 0 { log.Errorf("Gin: header not contain header: %s, global transaction xid", constant.XidKey) ctx.AbortWithStatus(http.StatusBadRequest) return } newCtx := ctx.Request.Context() newCtx = tm.InitSeataContext(newCtx) tm.SetXID(newCtx, xid) ctx.Request = ctx.Request.WithContext(newCtx) log.Infof("global transaction xid is :%s", xid) }
}
gin的中间件根据传递的xid新建context并且放到ctx.Request的上下文中 但是在示例代码中 func updateDataSuccessHandler(c *gin.Context) { log.Infof("get tm updateData") if err := updateDataSuccess(c); err != nil { c.JSON(http.StatusBadRequest, "updateData failure") return } c.JSON(http.StatusOK, "updateData ok") } 传递的都是gin.Context, 不是应该传递c.Request.Context给处理函数呢,发现最后传给db驱动的也是gin.Context,为啥是这样呢
The text was updated successfully, but these errors were encountered:
No branches or pull requests
// TransactionMiddleware filter gin invocation
// NOTE: when use gin,must set gin.ContextWithFallback true when gin version >= 1.8.1
func TransactionMiddleware() gin.HandlerFunc {
return func(ctx *gin.Context) {
xid := ctx.GetHeader(constant.XidKey)
if xid == "" {
xid = ctx.GetHeader(constant.XidKeyLowercase)
}
}
gin的中间件根据传递的xid新建context并且放到ctx.Request的上下文中
但是在示例代码中
func updateDataSuccessHandler(c *gin.Context) {
log.Infof("get tm updateData")
if err := updateDataSuccess(c); err != nil {
c.JSON(http.StatusBadRequest, "updateData failure")
return
}
c.JSON(http.StatusOK, "updateData ok")
}
传递的都是gin.Context, 不是应该传递c.Request.Context给处理函数呢,发现最后传给db驱动的也是gin.Context,为啥是这样呢
The text was updated successfully, but these errors were encountered: