Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2020-12-08 00:38:37 +03:00
parent f63ff80d46
commit b7b28f6b9a
29 changed files with 138 additions and 85 deletions

View File

@@ -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)
}

View File

@@ -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