From 547040cd5b7df652e8af46e5034adbe2130a01f1 Mon Sep 17 00:00:00 2001 From: haoyun Date: Tue, 16 Nov 2021 11:31:33 +0800 Subject: [PATCH] feat:support custom callopts on client side Signed-off-by: haoyun --- client.go | 11 +++++++---- client_opts.go | 9 +++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/client.go b/client.go index 0568f9209..3e535dd2c 100644 --- a/client.go +++ b/client.go @@ -124,14 +124,17 @@ func New(address string, opts ...ClientOpt) (*Client, error) { grpc.WithConnectParams(connParams), grpc.WithContextDialer(dialer.ContextDialer), grpc.WithReturnConnectionError(), - - // TODO(stevvooe): We may need to allow configuration of this on the client. - grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(defaults.DefaultMaxRecvMsgSize)), - grpc.WithDefaultCallOptions(grpc.MaxCallSendMsgSize(defaults.DefaultMaxSendMsgSize)), } if len(copts.dialOptions) > 0 { gopts = copts.dialOptions } + if len(copts.callOptions) > 0 { + gopts = append(gopts, grpc.WithDefaultCallOptions(copts.callOptions...)) + } else { + gopts = append(gopts, grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(defaults.DefaultMaxRecvMsgSize), + grpc.MaxCallSendMsgSize(defaults.DefaultMaxSendMsgSize))) + } if copts.defaultns != "" { unary, stream := newNSInterceptors(copts.defaultns) gopts = append(gopts, diff --git a/client_opts.go b/client_opts.go index 44feaa30a..2ef7575d8 100644 --- a/client_opts.go +++ b/client_opts.go @@ -34,6 +34,7 @@ type clientOpts struct { defaultPlatform platforms.MatchComparer services *services dialOptions []grpc.DialOption + callOptions []grpc.CallOption timeout time.Duration } @@ -75,6 +76,14 @@ func WithDialOpts(opts []grpc.DialOption) ClientOpt { } } +// WithCallOpts allows grpc.CallOptions to be set on the connection +func WithCallOpts(opts []grpc.CallOption) ClientOpt { + return func(c *clientOpts) error { + c.callOptions = opts + return nil + } +} + // WithServices sets services used by the client. func WithServices(opts ...ServicesOpt) ClientOpt { return func(c *clientOpts) error {