@@ -11,7 +11,6 @@ import (
1111 "github.com/rs/zerolog/log"
1212 "google.golang.org/grpc"
1313 gogrpc "google.golang.org/grpc"
14- "google.golang.org/grpc/credentials/insecure"
1514 "google.golang.org/grpc/keepalive"
1615)
1716
@@ -35,14 +34,22 @@ func (client *Client) Name() string {
3534}
3635
3736// Connect - connects to server
38- func (client * Client ) Connect (ctx context.Context ) error {
39- conn , err := gogrpc .Dial (
40- client .serverAddress ,
41- gogrpc .WithTransportCredentials (insecure .NewCredentials ()),
37+ func (client * Client ) Connect (ctx context.Context , opts ... ConnectOption ) error {
38+ dialOpts := []gogrpc.DialOption {
4239 gogrpc .WithKeepaliveParams (keepalive.ClientParameters {
4340 Time : 20 * time .Second ,
4441 Timeout : 10 * time .Second ,
4542 }),
43+ }
44+ connectOpts := newConnectOptions ()
45+ for i := range opts {
46+ opts [i ](& connectOpts )
47+ }
48+ dialOpts = append (dialOpts , gogrpc .WithTransportCredentials (connectOpts .creds ))
49+
50+ conn , err := gogrpc .Dial (
51+ client .serverAddress ,
52+ dialOpts ... ,
4653 )
4754 if err != nil {
4855 return errors .Wrap (err , "dial connection" )
@@ -53,15 +60,23 @@ func (client *Client) Connect(ctx context.Context) error {
5360}
5461
5562// WaitConnect - trying to connect to server
56- func (client * Client ) WaitConnect (ctx context.Context ) error {
57- conn , err := gogrpc .Dial (
58- client .serverAddress ,
63+ func (client * Client ) WaitConnect (ctx context.Context , opts ... ConnectOption ) error {
64+ dialOpts := []gogrpc.DialOption {
5965 gogrpc .WithBlock (),
60- gogrpc .WithTransportCredentials (insecure .NewCredentials ()),
6166 gogrpc .WithKeepaliveParams (keepalive.ClientParameters {
6267 Time : 20 * time .Second ,
6368 Timeout : 10 * time .Second ,
6469 }),
70+ }
71+ connectOpts := newConnectOptions ()
72+ for i := range opts {
73+ opts [i ](& connectOpts )
74+ }
75+ dialOpts = append (dialOpts , gogrpc .WithTransportCredentials (connectOpts .creds ))
76+
77+ conn , err := gogrpc .Dial (
78+ client .serverAddress ,
79+ dialOpts ... ,
6580 )
6681 if err != nil {
6782 return errors .Wrap (err , "dial connection" )
0 commit comments