github.com/qiniu/go-sdk/v7@v7.27.0/reqid/reqid.go (about)

     1  package reqid
     2  
     3  import (
     4  	"context"
     5  )
     6  
     7  type reqidKey struct{}
     8  
     9  // WithReqid 把reqid加入context中
    10  func WithReqid(ctx context.Context, reqid string) context.Context {
    11  	return context.WithValue(ctx, reqidKey{}, reqid)
    12  }
    13  
    14  // ReqidFromContext 从context中获取reqid
    15  func ReqidFromContext(ctx context.Context) (reqid string, ok bool) {
    16  	reqid, ok = ctx.Value(reqidKey{}).(string)
    17  	return
    18  }
    19  
    20  // --------------------------------------------------------------------