github.com/cheng762/platon-go@v1.8.17-0.20190529111256-7deff2d7be26/swarm/api/http/sctx.go (about) 1 package http 2 3 import ( 4 "context" 5 6 "github.com/PlatONnetwork/PlatON-Go/swarm/api" 7 "github.com/PlatONnetwork/PlatON-Go/swarm/sctx" 8 ) 9 10 type contextKey int 11 12 const ( 13 uriKey contextKey = iota 14 ) 15 16 func GetRUID(ctx context.Context) string { 17 v, ok := ctx.Value(sctx.HTTPRequestIDKey).(string) 18 if ok { 19 return v 20 } 21 return "xxxxxxxx" 22 } 23 24 func SetRUID(ctx context.Context, ruid string) context.Context { 25 return context.WithValue(ctx, sctx.HTTPRequestIDKey, ruid) 26 } 27 28 func GetURI(ctx context.Context) *api.URI { 29 v, ok := ctx.Value(uriKey).(*api.URI) 30 if ok { 31 return v 32 } 33 return nil 34 } 35 36 func SetURI(ctx context.Context, uri *api.URI) context.Context { 37 return context.WithValue(ctx, uriKey, uri) 38 }