feat:support custom callopts on client side
Signed-off-by: haoyun <yun.hao@daocloud.io>
This commit is contained in:
parent
7020719646
commit
547040cd5b
11
client.go
11
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,
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user