Dmitrii Stepanov
13fa0da374
After grpc upgrade there is no DialContext call. So connection is not actually established after created. Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
40 lines
1,018 B
Go
40 lines
1,018 B
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
// CallOption is a messaging session option within Protobuf RPC.
|
|
type CallOption func(*callParameters)
|
|
|
|
type callParameters struct {
|
|
ctx context.Context // nolint:containedctx
|
|
dialer func(context.Context, grpc.ClientConnInterface) error
|
|
}
|
|
|
|
func defaultCallParameters() *callParameters {
|
|
return &callParameters{
|
|
ctx: context.Background(),
|
|
}
|
|
}
|
|
|
|
// WithContext returns option to specify call context. If provided, all network
|
|
// communications will be based on this context. Otherwise, context.Background()
|
|
// is used.
|
|
//
|
|
// Context SHOULD NOT be nil.
|
|
func WithContext(ctx context.Context) CallOption {
|
|
return func(prm *callParameters) {
|
|
prm.ctx = ctx
|
|
}
|
|
}
|
|
|
|
// WithDialer returns option to specify grpc dialer. If passed, it will be
|
|
// called after the connection is successfully created.
|
|
func WithDialer(dialer func(context.Context, grpc.ClientConnInterface) error) CallOption {
|
|
return func(prm *callParameters) {
|
|
prm.dialer = dialer
|
|
}
|
|
}
|