diff --git a/internal/pkg/middleware/requestid.go b/internal/pkg/middleware/requestid.go index dc1ac15..b4c0a5d 100644 --- a/internal/pkg/middleware/requestid.go +++ b/internal/pkg/middleware/requestid.go @@ -33,19 +33,14 @@ func RequestID() gin.HandlerFunc { return func(ctx *gin.Context) { var rid string - if rid = ctx.GetString(requestID); rid != "" { - // request id exists already - ctx.Next() - } - if rid = ctx.GetHeader(requestID); rid != "" { - ctx.Set(requestID, rid) + ctx.Request.Header.Add(requestID, rid) ctx.Next() } rid = uuid.NewString() - ctx.Set(requestID, rid) - ctx.Writer.Header().Add(requestID, rid) + ctx.Request.Header.Add(requestID, rid) + ctx.Header(requestID, rid) ctx.Next() } } diff --git a/internal/pkg/middleware/requestid_test.go b/internal/pkg/middleware/requestid_test.go index 9ead114..db5f917 100644 --- a/internal/pkg/middleware/requestid_test.go +++ b/internal/pkg/middleware/requestid_test.go @@ -58,12 +58,12 @@ func TestRequestID(t *testing.T) { wanted := "123" r.GET("/example", func(c *gin.Context) { - got = c.GetString(requestID) + got = c.GetHeader(requestID) c.Status(http.StatusOK) }) r.POST("/example", func(c *gin.Context) { - got = c.GetString(requestID) + got = c.GetHeader(requestID) c.String(http.StatusAccepted, "ok") })