// Copyright 2019 github.com. All rights reserved. // Use of this source code is governed by github.com. package id import ( "context" "fmt" "strconv" ) // GetUniqueID 获取唯一id (分布式) func GetUniqueID() (uint64, error) { if sf == nil { return 0, fmt.Errorf("sf is nil.") } return sf.NextID() } // GetRequestId 生成request id // 如果开启了jaeger trace,则使用其生成的trace id 作为request id func GetRequestId(ctx context.Context) string { if rid, ok := ctx.Value("RequestId").(string); ok && rid != "" { return rid } id, _ := GetUniqueID() newId := strconv.Itoa(int(id)) ctx = context.WithValue(ctx, "RequestId", newId) return newId }