@@ -6,11 +6,13 @@ import (
|
||||
|
||||
type storeKey struct{}
|
||||
|
||||
func storeContext(ctx context.Context) (Store, bool) {
|
||||
// FromContext get store from context
|
||||
func FromContext(ctx context.Context) (Store, bool) {
|
||||
c, ok := ctx.Value(storeKey{}).(Store)
|
||||
return c, ok
|
||||
}
|
||||
|
||||
// NewContext put store in context
|
||||
func NewContext(ctx context.Context, c Store) context.Context {
|
||||
return context.WithValue(ctx, storeKey{}, c)
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ type Options struct {
|
||||
Context context.Context
|
||||
}
|
||||
|
||||
// NewOptions creates options struct
|
||||
func NewOptions(opts ...Option) Options {
|
||||
options := Options{
|
||||
Logger: logger.DefaultLogger,
|
||||
@@ -37,6 +38,7 @@ func NewOptions(opts ...Option) Options {
|
||||
// Option sets values in Options
|
||||
type Option func(o *Options)
|
||||
|
||||
// Context pass context to store
|
||||
func Context(ctx context.Context) Option {
|
||||
return func(o *Options) {
|
||||
o.Context = ctx
|
||||
|
||||
Reference in New Issue
Block a user