github.com/linapex/ethereum-go-chinese@v0.0.0-20190316121929-f8b7a73c3fa1/swarm/api/http/sctx.go (about)

     1  
     2  //<developer>
     3  //    <name>linapex 曹一峰</name>
     4  //    <email>linapex@163.com</email>
     5  //    <wx>superexc</wx>
     6  //    <qqgroup>128148617</qqgroup>
     7  //    <url>https://jsq.ink</url>
     8  //    <role>pku engineer</role>
     9  //    <date>2019-03-16 19:16:43</date>
    10  //</624450112004820992>
    11  
    12  package http
    13  
    14  import (
    15  	"context"
    16  
    17  	"github.com/ethereum/go-ethereum/swarm/api"
    18  	"github.com/ethereum/go-ethereum/swarm/sctx"
    19  )
    20  
    21  type uriKey struct{}
    22  
    23  func GetRUID(ctx context.Context) string {
    24  	v, ok := ctx.Value(sctx.HTTPRequestIDKey{}).(string)
    25  	if ok {
    26  		return v
    27  	}
    28  	return "xxxxxxxx"
    29  }
    30  
    31  func SetRUID(ctx context.Context, ruid string) context.Context {
    32  	return context.WithValue(ctx, sctx.HTTPRequestIDKey{}, ruid)
    33  }
    34  
    35  func GetURI(ctx context.Context) *api.URI {
    36  	v, ok := ctx.Value(uriKey{}).(*api.URI)
    37  	if ok {
    38  		return v
    39  	}
    40  	return nil
    41  }
    42  
    43  func SetURI(ctx context.Context, uri *api.URI) context.Context {
    44  	return context.WithValue(ctx, uriKey{}, uri)
    45  }
    46