feat(requestid): reqID in the header
This commit is contained in:
		@ -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
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user