utils.go 376 Bytes
Newer Older
chenweijian's avatar
chenweijian committed
1 2 3
package route

import (
hujiebin's avatar
hujiebin committed
4 5
	"git.hilo.cn/hilo-common/mycontext"
	"github.com/gin-gonic/gin"
chenweijian's avatar
chenweijian committed
6 7 8 9
	uuid "github.com/satori/go.uuid"
	"strings"
)

hujiebin's avatar
hujiebin committed
10 11 12 13
func genTraceId(c *gin.Context) string {
	if trace := c.GetHeader(mycontext.TRACEID); len(trace) > 0 {
		return trace
	}
chenweijian's avatar
chenweijian committed
14 15 16 17
	traceId := strings.Replace(uuid.NewV4().String(), "-", "", -1)
	traceId = traceId[:len(traceId)/2]
	return traceId
}