feat(requestid): handle the case for new uuid
This commit is contained in:
		@ -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)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user