26 lines
639 B
Go
26 lines
639 B
Go
package middleware
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/nose7en/ToyBoomServer/common"
|
|
"github.com/nose7en/ToyBoomServer/utils"
|
|
)
|
|
|
|
func Trace() func(c *gin.Context) {
|
|
return func(c *gin.Context) {
|
|
UpStreamTraceID := c.GetHeader(common.TraceIDKey)
|
|
if len(UpStreamTraceID) > 0 {
|
|
c.Set(common.TraceIDKey, UpStreamTraceID)
|
|
common.Logger(c).Infof("get a common request, upstream traceid %v",
|
|
c.GetString(common.TraceIDKey))
|
|
c.Next()
|
|
return
|
|
}
|
|
|
|
c.Set(common.TraceIDKey, utils.GenerateUID())
|
|
common.Logger(c).Infof("get a common request, gen traceid %v",
|
|
c.GetString(common.TraceIDKey))
|
|
c.Next()
|
|
}
|
|
}
|