utils.go 376 Bytes
Newer Older
hujiebin's avatar
hujiebin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
package route

import (
	"git.hilo.cn/hilo-common/mycontext"
	"github.com/gin-gonic/gin"
	uuid "github.com/satori/go.uuid"
	"strings"
)

func genTraceId(c *gin.Context) string {
	if trace := c.GetHeader(mycontext.TRACEID); len(trace) > 0 {
		return trace
	}
	traceId := strings.Replace(uuid.NewV4().String(), "-", "", -1)
	traceId = traceId[:len(traceId)/2]
	return traceId
}