2020-12-07 16:10:20 +03:00
|
|
|
package store
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
)
|
|
|
|
|
|
|
|
type storeKey struct{}
|
|
|
|
|
2020-12-08 00:38:37 +03:00
|
|
|
// FromContext get store from context
|
|
|
|
func FromContext(ctx context.Context) (Store, bool) {
|
2020-12-17 22:52:00 +03:00
|
|
|
if ctx == nil {
|
|
|
|
return nil, false
|
|
|
|
}
|
2020-12-07 16:10:20 +03:00
|
|
|
c, ok := ctx.Value(storeKey{}).(Store)
|
|
|
|
return c, ok
|
|
|
|
}
|
|
|
|
|
2020-12-08 00:38:37 +03:00
|
|
|
// NewContext put store in context
|
2020-12-07 16:10:20 +03:00
|
|
|
func NewContext(ctx context.Context, c Store) context.Context {
|
2020-12-17 22:52:00 +03:00
|
|
|
if ctx == nil {
|
|
|
|
ctx = context.Background()
|
|
|
|
}
|
2020-12-07 16:10:20 +03:00
|
|
|
return context.WithValue(ctx, storeKey{}, c)
|
|
|
|
}
|