github.com/linapex/ethereum-dpos-chinese@v0.0.0-20190316121959-b78b3a4a1ece/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 12:09:46</date>
    10  //</624342669425905664>
    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 contextKey int
    22  
    23  const (
    24  	uriKey contextKey = iota
    25  )
    26  
    27  func GetRUID(ctx context.Context) string {
    28  	v, ok := ctx.Value(sctx.HTTPRequestIDKey).(string)
    29  	if ok {
    30  		return v
    31  	}
    32  	return "xxxxxxxx"
    33  }
    34  
    35  func SetRUID(ctx context.Context, ruid string) context.Context {
    36  	return context.WithValue(ctx, sctx.HTTPRequestIDKey, ruid)
    37  }
    38  
    39  func GetURI(ctx context.Context) *api.URI {
    40  	v, ok := ctx.Value(uriKey).(*api.URI)
    41  	if ok {
    42  		return v
    43  	}
    44  	return nil
    45  }
    46  
    47  func SetURI(ctx context.Context, uri *api.URI) context.Context {
    48  	return context.WithValue(ctx, uriKey, uri)
    49  }
    50