feat(requestid): put the request id to the response

This commit is contained in:
Muyao CHEN 2024-10-03 14:06:19 +02:00
parent ad1d4de7c3
commit 7886788c35
2 changed files with 4 additions and 1 deletions

View File

@ -23,5 +23,7 @@ func RequestID() gin.HandlerFunc {
rid = uuid.NewString() rid = uuid.NewString()
ctx.Set(requestID, rid) ctx.Set(requestID, rid)
ctx.Writer.Header().Add(requestID, rid)
ctx.Next()
} }
} }

View File

@ -49,7 +49,8 @@ func TestRequestID(t *testing.T) {
_ = performRequest(r, "GET", "/example?a=100", header{requestID, wanted}) _ = performRequest(r, "GET", "/example?a=100", header{requestID, wanted})
assert.Equal(t, "123", got) assert.Equal(t, "123", got)
_ = performRequest(r, "GET", "/example?a=100") res := performRequest(r, "GET", "/example?a=100")
assert.NotEqual(t, "", got) assert.NotEqual(t, "", got)
assert.NoError(t, uuid.Validate(got)) assert.NoError(t, uuid.Validate(got))
assert.Equal(t, res.Header()[requestID][0], got)
} }