sctx.go 687 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package http
  2. import (
  3. "context"
  4. "github.com/ethereum/go-ethereum/swarm/api"
  5. "github.com/ethereum/go-ethereum/swarm/sctx"
  6. )
  7. type contextKey int
  8. const (
  9. uriKey contextKey = iota
  10. )
  11. func GetRUID(ctx context.Context) string {
  12. v, ok := ctx.Value(sctx.HTTPRequestIDKey).(string)
  13. if ok {
  14. return v
  15. }
  16. return "xxxxxxxx"
  17. }
  18. func SetRUID(ctx context.Context, ruid string) context.Context {
  19. return context.WithValue(ctx, sctx.HTTPRequestIDKey, ruid)
  20. }
  21. func GetURI(ctx context.Context) *api.URI {
  22. v, ok := ctx.Value(uriKey).(*api.URI)
  23. if ok {
  24. return v
  25. }
  26. return nil
  27. }
  28. func SetURI(ctx context.Context, uri *api.URI) context.Context {
  29. return context.WithValue(ctx, uriKey, uri)
  30. }