context.go

 1package store
 2
 3import "context"
 4
 5var contextKey = &struct{ string }{"store"}
 6
 7// FromContext returns the store from the context.
 8func FromContext(ctx context.Context) Store {
 9	if store, ok := ctx.Value(contextKey).(Store); ok {
10		return store
11	}
12	return nil
13}
14
15// WithContext returns a new context with the store attached.
16func WithContext(ctx context.Context, store Store) context.Context {
17	return context.WithValue(ctx, contextKey, store)
18}