swarm: modify context key (#17925)

* swarm: modify context key

* gofmt sctx.go
This commit is contained in:
KimMachineGun
2018-11-06 17:54:19 +09:00
committed by Viktor Trón
parent 126dfde6c9
commit baee850471
2 changed files with 10 additions and 16 deletions

View File

@ -2,19 +2,17 @@ package sctx
import "context"
type ContextKey int
const (
HTTPRequestIDKey ContextKey = iota
requestHostKey
type (
HTTPRequestIDKey struct{}
requestHostKey struct{}
)
func SetHost(ctx context.Context, domain string) context.Context {
return context.WithValue(ctx, requestHostKey, domain)
return context.WithValue(ctx, requestHostKey{}, domain)
}
func GetHost(ctx context.Context) string {
v, ok := ctx.Value(requestHostKey).(string)
v, ok := ctx.Value(requestHostKey{}).(string)
if ok {
return v
}