[#286] client: Add TLS options

Add `WithTLSConfig` option to client.
If it is not nil then client will
try to open secured connection.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-05-20 18:51:28 +03:00 committed by Leonard Lyubich
parent 634e405e9c
commit 89aede1fb3
3 changed files with 35 additions and 2 deletions

View file

@ -1,6 +1,7 @@
package client
import (
"crypto/tls"
"time"
"google.golang.org/grpc"
@ -14,6 +15,8 @@ type cfg struct {
dialTimeout time.Duration
tlsCfg *tls.Config
conn *grpc.ClientConn
}
@ -49,6 +52,18 @@ func WithDialTimeout(v time.Duration) Option {
}
}
// WithTLSCfg returns option to specify
// TLS configuration.
//
// Ignored if WithGRPCConn is provided.
func WithTLSCfg(v *tls.Config) Option {
return func(c *cfg) {
if v != nil {
c.tlsCfg = v
}
}
}
// WithGRPCConn returns option to specify
// gRPC virtual connection.
func WithGRPCConn(v *grpc.ClientConn) Option {