github.com/yinchengtsinghua/golang-Eos-dpos-Ethereum@v0.0.0-20190121132951-92cc4225ed8e/swarm/sctx/sctx.go (about)

     1  
     2  //此源码被清华学神尹成大魔王专业翻译分析并修改
     3  //尹成QQ77025077
     4  //尹成微信18510341407
     5  //尹成所在QQ群721929980
     6  //尹成邮箱 yinc13@mails.tsinghua.edu.cn
     7  //尹成毕业于清华大学,微软区块链领域全球最有价值专家
     8  //https://mvp.microsoft.com/zh-cn/PublicProfile/4033620
     9  package sctx
    10  
    11  import "context"
    12  
    13  type ContextKey int
    14  
    15  const (
    16  	HTTPRequestIDKey ContextKey = iota
    17  	requestHostKey
    18  )
    19  
    20  func SetHost(ctx context.Context, domain string) context.Context {
    21  	return context.WithValue(ctx, requestHostKey, domain)
    22  }
    23  
    24  func GetHost(ctx context.Context) string {
    25  	v, ok := ctx.Value(requestHostKey).(string)
    26  	if ok {
    27  		return v
    28  	}
    29  	return ""
    30  }