feat(requestid): reqID in the header
This commit is contained in:
parent
7024c76032
commit
2a52fb6b88
@ -2,8 +2,19 @@ package middleware
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
const requestID = "X-Request-Id"
|
||||
|
||||
func RequestID() gin.HandlerFunc {
|
||||
return func(ctx *gin.Context) {
|
||||
ctx.Set("X-Request-Id", "123")
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,8 +9,6 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
const requestID = "X-Request-Id"
|
||||
|
||||
type header struct {
|
||||
Key string
|
||||
Value string
|
||||
|
Loading…
Reference in New Issue
Block a user