feat(requestid): handle the case for new uuid

This commit is contained in:
Muyao CHEN
2024-10-03 13:53:30 +02:00
parent d870d2a58d
commit e6389f0fd2
3 changed files with 11 additions and 2 deletions

View File

@ -1,6 +1,9 @@
package middleware
import "github.com/gin-gonic/gin"
import (
"github.com/gin-gonic/gin"
"github.com/google/uuid"
)
const requestID = "X-Request-Id"
@ -15,7 +18,10 @@ func RequestID() gin.HandlerFunc {
if rid = ctx.GetHeader(requestID); rid != "" {
ctx.Set(requestID, rid)
ctx.Next()
}
ctx.Set("X-Request-Id", "123")
rid = uuid.NewString()
ctx.Set(requestID, rid)
}
}