client: allow to create new client with predefined call options

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2020-12-15 23:09:51 +03:00
parent f14efa64f0
commit 70a17dc10a
3 changed files with 23 additions and 109 deletions

View File

@@ -0,0 +1,23 @@
package client
import (
"context"
)
type clientCallOptions struct {
Client
opts []CallOption
}
func (s *clientCallOptions) Call(ctx context.Context, req Request, rsp interface{}, opts ...CallOption) error {
return s.Client.Call(ctx, req, rsp, append(s.opts, opts...)...)
}
func (s *clientCallOptions) Stream(ctx context.Context, req Request, opts ...CallOption) (Stream, error) {
return s.Client.Stream(ctx, req, append(s.opts, opts...)...)
}
// NewClientCallOptions add CallOption to every call
func NewClientCallOptions(c Client, opts ...CallOption) Client {
return &clientCallOptions{c, opts}
}