Skip to content

Commit

Permalink
client: add call option helper
Browse files Browse the repository at this point in the history
Signed-off-by: Vasiliy Tolstov <[email protected]>
  • Loading branch information
vtolstov committed Jan 18, 2021
1 parent 77f517a commit 2b2bcf4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions api/router/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ 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"
)

type Options struct {
Handler string
Registry registry.Registry
Resolver resolver.Resolver
Logger logger.Logger
Context context.Context
}

Expand Down
10 changes: 10 additions & 0 deletions client/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 2b2bcf4

Please sign in to comment.