Conceptual deliverable

This commit is contained in:
orb li 2019-10-10 13:55:16 +08:00
parent 226d55d752
commit 77108771db
2 changed files with 14 additions and 14 deletions

View File

@ -109,7 +109,7 @@ func (g *grpcClient) call(ctx context.Context, node *registry.Node, req client.R
maxSendMsgSize := g.maxSendMsgSizeValue() maxSendMsgSize := g.maxSendMsgSizeValue()
var grr error var grr error
grpcDialOptions := []grpc.DialOption{ grpcDialOptions := []grpc.DialOption{
grpc.WithDefaultCallOptions(grpc.ForceCodec(cf)), grpc.WithDefaultCallOptions(grpc.ForceCodec(cf)),
grpc.WithTimeout(opts.DialTimeout), grpc.WithTimeout(opts.DialTimeout),
@ -119,7 +119,7 @@ func (g *grpcClient) call(ctx context.Context, node *registry.Node, req client.R
grpc.MaxCallSendMsgSize(maxSendMsgSize), grpc.MaxCallSendMsgSize(maxSendMsgSize),
), ),
} }
if opts := g.getGrpcDialOptions(); opts != nil { if opts := g.getGrpcDialOptions(); opts != nil {
grpcDialOptions = append(grpcDialOptions, opts...) grpcDialOptions = append(grpcDialOptions, opts...)
} }
@ -187,12 +187,12 @@ func (g *grpcClient) stream(ctx context.Context, node *registry.Node, req client
defer cancel() defer cancel()
wc := wrapCodec{cf} wc := wrapCodec{cf}
grpcDialOptions := []grpc.DialOption{ grpcDialOptions := []grpc.DialOption{
grpc.WithDefaultCallOptions(grpc.ForceCodec(wc)), grpc.WithDefaultCallOptions(grpc.ForceCodec(wc)),
g.secure(), g.secure(),
} }
if opts := g.getGrpcDialOptions(); opts != nil { if opts := g.getGrpcDialOptions(); opts != nil {
grpcDialOptions = append(grpcDialOptions, opts...) grpcDialOptions = append(grpcDialOptions, opts...)
} }
@ -541,11 +541,11 @@ func (g *grpcClient) String() string {
} }
func (g *grpcClient) getGrpcDialOptions() []grpc.DialOption { func (g *grpcClient) getGrpcDialOptions() []grpc.DialOption {
if g.opts.Context == nil { if g.opts.CallOptions.Context == nil {
return nil return nil
} }
v := g.opts.Context.Value(grpcDialOptions{}) v := g.opts.CallOptions.Context.Value(grpcDialOptions{})
if v == nil { if v == nil {
return nil return nil

View File

@ -79,8 +79,8 @@ func MaxSendMsgSize(s int) client.Option {
// //
// DialOptions to be used to configure gRPC dial options // DialOptions to be used to configure gRPC dial options
// //
func DialOptions(opts ...grpc.DialOption) client.Option { func DialOptions(opts ...grpc.DialOption) client.CallOption {
return func(o *client.Options) { return func(o *client.CallOptions) {
if o.Context == nil { if o.Context == nil {
o.Context = context.Background() o.Context = context.Background()
} }
@ -91,11 +91,11 @@ func DialOptions(opts ...grpc.DialOption) client.Option {
// //
// CallOptions to be used to configure gRPC call options // CallOptions to be used to configure gRPC call options
// //
func CallOptions(opts ...grpc.CallOption) client.Option { func CallOptions(opts ...grpc.CallOption) client.CallOption {
return func(o *client.Options) { return func(o *client.CallOptions) {
if o.CallOptions.Context == nil { if o.Context == nil {
o.CallOptions.Context = context.Background() o.Context = context.Background()
} }
o.CallOptions.Context = context.WithValue(o.CallOptions.Context, grpcCallOptions{}, opts) o.Context = context.WithValue(o.Context, grpcCallOptions{}, opts)
} }
} }