github.com/oskarth/go-ethereum@v1.6.8-0.20191013093314-dac24a9d3494/swarm/api/http/sctx.go (about)

     1  package http
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/ethereum/go-ethereum/swarm/api"
     7  	"github.com/ethereum/go-ethereum/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  }