client: add call option helper

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2021-01-18 23:48:50 +03:00
parent 77f517a9f6
commit 2b2bcf4586
2 changed files with 12 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import (
"github.com/unistack-org/micro/v3/api/resolver"
"github.com/unistack-org/micro/v3/api/resolver/vpath"
"github.com/unistack-org/micro/v3/logger"
"github.com/unistack-org/micro/v3/registry"
)
@ -12,6 +13,7 @@ type Options struct {
Handler string
Registry registry.Registry
Resolver resolver.Resolver
Logger logger.Logger
Context context.Context
}

View File

@ -32,3 +32,13 @@ func SetPublishOption(k, v interface{}) PublishOption {
o.Context = context.WithValue(o.Context, k, v)
}
}
// SetCallOption returns a function to setup a context with given value
func SetCallOption(k, v interface{}) CallOption {
return func(o *CallOptions) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, k, v)
}
}