github.com/alexdevranger/node-1.8.27@v0.0.0-20221128213301-aa5841e41d2d/swarm/api/http/sctx.go (about)

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