feat(requestid): put the request id to the response
This commit is contained in:
		@ -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()
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -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)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user