diff --git a/config/context.go b/config/context.go new file mode 100644 index 00000000..e3c251a2 --- /dev/null +++ b/config/context.go @@ -0,0 +1,26 @@ +package config + +import ( + "context" +) + +type configKey struct{} + +func FromContext(ctx context.Context) (Config, bool) { + c, ok := ctx.Value(configKey{}).(Config) + return c, ok +} + +func NewContext(ctx context.Context, c Config) context.Context { + return context.WithValue(ctx, configKey{}, c) +} + +// SetOption returns a function to setup a context with given value +func SetOption(k, v interface{}) Option { + return func(o *Options) { + if o.Context == nil { + o.Context = context.Background() + } + o.Context = context.WithValue(o.Context, k, v) + } +} diff --git a/logger/context.go b/logger/context.go index ebe7f5e1..70056fa4 100644 --- a/logger/context.go +++ b/logger/context.go @@ -14,3 +14,13 @@ func FromContext(ctx context.Context) (Logger, bool) { func NewContext(ctx context.Context, l Logger) context.Context { return context.WithValue(ctx, loggerKey{}, l) } + +// SetOption returns a function to setup a context with given value +func SetOption(k, v interface{}) Option { + return func(o *Options) { + if o.Context == nil { + o.Context = context.Background() + } + o.Context = context.WithValue(o.Context, k, v) + } +} diff --git a/logger/options.go b/logger/options.go index 8bc045de..0bfd2a42 100644 --- a/logger/options.go +++ b/logger/options.go @@ -69,12 +69,3 @@ func WithContext(ctx context.Context) Option { args.Context = ctx } } - -func SetOption(k, v interface{}) Option { - return func(o *Options) { - if o.Context == nil { - o.Context = context.Background() - } - o.Context = context.WithValue(o.Context, k, v) - } -} diff --git a/mapping.txt b/mapping.txt deleted file mode 100644 index e4c0086e..00000000 --- a/mapping.txt +++ /dev/null @@ -1,2 +0,0 @@ -client/grpc/* micro-client-grpc -#server/grpc/* micro-server-grpc diff --git a/network/transport/context.go b/network/transport/context.go new file mode 100644 index 00000000..eace44a4 --- /dev/null +++ b/network/transport/context.go @@ -0,0 +1,26 @@ +package transport + +import ( + "context" +) + +type transportKey struct{} + +func FromContext(ctx context.Context) (Transport, bool) { + c, ok := ctx.Value(transportKey{}).(Transport) + return c, ok +} + +func NewContext(ctx context.Context, c Transport) context.Context { + return context.WithValue(ctx, transportKey{}, c) +} + +// SetOption returns a function to setup a context with given value +func SetOption(k, v interface{}) Option { + return func(o *Options) { + if o.Context == nil { + o.Context = context.Background() + } + o.Context = context.WithValue(o.Context, k, v) + } +} diff --git a/pull.sh b/pull.sh deleted file mode 100755 index c1981d92..00000000 --- a/pull.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/bash -ex - -if [ "$1" == "--force" ]; then - force="yes" -fi - -srcsha="--root" -dstsha="HEAD" -commitrange="${srcsha} ${dstsha}" - -while read srcpath dstpath; do - if [ "${srcpath::1}" == "#" ] ; then - continue - fi - - relpath="${srcpath//\*}" - - rm -rf patches/ - - dstsha=$(git rev-parse HEAD) - if [ -f "../${dstpath}/.synced" ]; then - srcsha=$(cat "../${dstpath}/.synced" | tr -d '\n') - commitrange="${srcsha}..${dstsha}" - fi - - git format-patch --find-copies --break-rewrites --find-renames=100% --relative="${relpath}" --no-stat --minimal --minimal --no-cover-letter --no-signature "${commitrange}" -o patches/ -- "${srcpath}" - - for p in $(ls patches/); do - grep -q 'From: Vasiliy Tolstov /dev/null - git am --rerere-autoupdate --3way ../micro/patches/*.patch - popd >/dev/null - fi - - echo -n "${dstsha}" > ../${dstpath}/.synced - -done < mapping.txt - diff --git a/registry/context.go b/registry/context.go new file mode 100644 index 00000000..ee7c4ec1 --- /dev/null +++ b/registry/context.go @@ -0,0 +1,26 @@ +package registry + +import ( + "context" +) + +type registryKey struct{} + +func FromContext(ctx context.Context) (Registry, bool) { + c, ok := ctx.Value(registryKey{}).(Registry) + return c, ok +} + +func NewContext(ctx context.Context, c Registry) context.Context { + return context.WithValue(ctx, registryKey{}, c) +} + +// SetOption returns a function to setup a context with given value +func SetOption(k, v interface{}) Option { + return func(o *Options) { + if o.Context == nil { + o.Context = context.Background() + } + o.Context = context.WithValue(o.Context, k, v) + } +} diff --git a/server/context.go b/server/context.go index cbce8c45..e57e57ca 100644 --- a/server/context.go +++ b/server/context.go @@ -17,7 +17,7 @@ func NewContext(ctx context.Context, s Server) context.Context { return context.WithValue(ctx, serverKey{}, s) } -// Setoption returns a function to setup a context with given value +// SetOption returns a function to setup a context with given value func SetOption(k, v interface{}) Option { return func(o *Options) { if o.Context == nil { diff --git a/store/context.go b/store/context.go new file mode 100644 index 00000000..10d495ce --- /dev/null +++ b/store/context.go @@ -0,0 +1,26 @@ +package store + +import ( + "context" +) + +type storeKey struct{} + +func storeContext(ctx context.Context) (Store, bool) { + c, ok := ctx.Value(storeKey{}).(Store) + return c, ok +} + +func NewContext(ctx context.Context, c Store) context.Context { + return context.WithValue(ctx, storeKey{}, c) +} + +// SetOption returns a function to setup a context with given value +func SetOption(k, v interface{}) Option { + return func(o *Options) { + if o.Context == nil { + o.Context = context.Background() + } + o.Context = context.WithValue(o.Context, k, v) + } +}