github.com/yinchengtsinghua/golang-Eos-dpos-Ethereum@v0.0.0-20190121132951-92cc4225ed8e/swarm/api/http/sctx.go (about) 1 2 //此源码被清华学神尹成大魔王专业翻译分析并修改 3 //尹成QQ77025077 4 //尹成微信18510341407 5 //尹成所在QQ群721929980 6 //尹成邮箱 yinc13@mails.tsinghua.edu.cn 7 //尹成毕业于清华大学,微软区块链领域全球最有价值专家 8 //https://mvp.microsoft.com/zh-cn/PublicProfile/4033620 9 package http 10 11 import ( 12 "context" 13 14 "github.com/ethereum/go-ethereum/swarm/api" 15 "github.com/ethereum/go-ethereum/swarm/sctx" 16 ) 17 18 type contextKey int 19 20 const ( 21 uriKey contextKey = iota 22 ) 23 24 func GetRUID(ctx context.Context) string { 25 v, ok := ctx.Value(sctx.HTTPRequestIDKey).(string) 26 if ok { 27 return v 28 } 29 return "xxxxxxxx" 30 } 31 32 func SetRUID(ctx context.Context, ruid string) context.Context { 33 return context.WithValue(ctx, sctx.HTTPRequestIDKey, ruid) 34 } 35 36 func GetURI(ctx context.Context) *api.URI { 37 v, ok := ctx.Value(uriKey).(*api.URI) 38 if ok { 39 return v 40 } 41 return nil 42 } 43 44 func SetURI(ctx context.Context, uri *api.URI) context.Context { 45 return context.WithValue(ctx, uriKey, uri) 46 }