github.com/linapex/ethereum-go-chinese@v0.0.0-20190316121929-f8b7a73c3fa1/swarm/sctx/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:44</date>
    10  //</624450117272866816>
    11  
    12  package sctx
    13  
    14  import "context"
    15  
    16  type (
    17  	HTTPRequestIDKey struct{}
    18  	requestHostKey   struct{}
    19  )
    20  
    21  func SetHost(ctx context.Context, domain string) context.Context {
    22  	return context.WithValue(ctx, requestHostKey{}, domain)
    23  }
    24  
    25  func GetHost(ctx context.Context) string {
    26  	v, ok := ctx.Value(requestHostKey{}).(string)
    27  	if ok {
    28  		return v
    29  	}
    30  	return ""
    31  }
    32