musereborn opened a new issue, #49:
URL: https://github.com/apache/incubator-seata-go-samples/issues/49

   // 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,为啥是这样呢
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@seata.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@seata.apache.org
For additional commands, e-mail: dev-h...@seata.apache.org

Reply via email to