From 31d1f76c41b6ef4654aed69170ca0b027ebdf573 Mon Sep 17 00:00:00 2001 From: straysh Date: Fri, 23 Sep 2022 20:16:20 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dkratos=E7=9A=84context?= =?UTF-8?q?=E4=BC=A0=E9=80=92=E5=88=B0gin=E4=B8=A2=E5=A4=B1=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在kratos中间件结束时,将最后收到的context绑定到gin的`c.Request`,以便在gin内可以检索到下层的context。 --- gin.go | 1 + 1 file changed, 1 insertion(+) diff --git a/gin.go b/gin.go index cbf1476..c676583 100644 --- a/gin.go +++ b/gin.go @@ -61,6 +61,7 @@ func Middlewares(m ...middleware.Middleware) gin.HandlerFunc { chain := middleware.Chain(m...) return func(c *gin.Context) { next := func(ctx context.Context, req interface{}) (interface{}, error) { + c.Request = c.Request.WithContext(ctx) c.Next() var err error if c.Writer.Status() >= http.StatusBadRequest {