[#2] rpc/client: Allow to override low-level gRPC options
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
cc8da15242
commit
45358d4551
3 changed files with 31 additions and 17 deletions
|
@ -5,6 +5,8 @@ import (
|
|||
"time"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
"google.golang.org/grpc/keepalive"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -21,19 +23,28 @@ type cfg struct {
|
|||
dialTimeout time.Duration
|
||||
rwTimeout time.Duration
|
||||
|
||||
tlsCfg *tls.Config
|
||||
tlsCfg *tls.Config
|
||||
grpcDialOpts []grpc.DialOption
|
||||
|
||||
conn *grpc.ClientConn
|
||||
}
|
||||
|
||||
const (
|
||||
defaultDialTimeout = 5 * time.Second
|
||||
defaultRWTimeout = 1 * time.Minute
|
||||
defaultDialTimeout = 5 * time.Second
|
||||
defaultKeepAliveTimeout = 5 * time.Second
|
||||
defaultRWTimeout = 1 * time.Minute
|
||||
)
|
||||
|
||||
func (c *cfg) initDefault() {
|
||||
c.dialTimeout = defaultDialTimeout
|
||||
c.rwTimeout = defaultRWTimeout
|
||||
c.grpcDialOpts = []grpc.DialOption{
|
||||
grpc.WithBlock(),
|
||||
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
||||
grpc.WithKeepaliveParams(keepalive.ClientParameters{
|
||||
Timeout: defaultKeepAliveTimeout,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
// WithNetworkAddress returns option to specify
|
||||
|
@ -115,3 +126,10 @@ func WithGRPCConn(v *grpc.ClientConn) Option {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// WithGRPCDialOptions returns an option to specify grpc.DialOption.
|
||||
func WithGRPCDialOptions(opts []grpc.DialOption) Option {
|
||||
return func(c *cfg) {
|
||||
c.grpcDialOpts = append(c.grpcDialOpts, opts...)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue