x/internal/util/selector/key.go
2022-09-02 21:53:50 +08:00

28 lines
412 B
Go

package selector
import (
"context"
)
type hashKey struct{}
type Hash struct {
Source string
Value int
}
var (
clientHashKey = &hashKey{}
)
func ContextWithHash(ctx context.Context, hash *Hash) context.Context {
return context.WithValue(ctx, clientHashKey, hash)
}
func HashFromContext(ctx context.Context) *Hash {
if v, _ := ctx.Value(clientHashKey).(*Hash); v != nil {
return v
}
return nil
}