From 092f1f08f86a217c9aca91520b369255cacef56d Mon Sep 17 00:00:00 2001 From: Fernando Sobreira Date: Tue, 16 Mar 2021 13:37:50 -0300 Subject: [PATCH] add dial option on grpc start --- cmd/subcommands/root.go | 3 ++- pkg/client/client.go | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/cmd/subcommands/root.go b/cmd/subcommands/root.go index 52c25b570..ac55b5db2 100644 --- a/cmd/subcommands/root.go +++ b/cmd/subcommands/root.go @@ -22,6 +22,7 @@ import ( "github.com/spf13/cobra" "github.com/spf13/cobra/doc" "golang.org/x/crypto/ssh/terminal" + "google.golang.org/grpc" ) var ( @@ -55,7 +56,7 @@ var ( node = node + ":50051" } conn = client.NewGrpcClient(node) - if err := conn.Start(); err != nil { + if err := conn.Start(grpc.WithInsecure()); err != nil { return err } diff --git a/pkg/client/client.go b/pkg/client/client.go index 4eb84a6f7..13f6d4dd0 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -14,6 +14,7 @@ type GrpcClient struct { Conn *grpc.ClientConn Client api.WalletClient grpcTimeout time.Duration + opts []grpc.DialOption } // NewGrpcClient create grpc controller @@ -40,12 +41,13 @@ func (g *GrpcClient) SetTimeout(timeout time.Duration) { } // Start initiate grpc connection -func (g *GrpcClient) Start() error { +func (g *GrpcClient) Start(opts ...grpc.DialOption) error { var err error if len(g.Address) == 0 { g.Address = "grp.trongrid.io:50051" } - g.Conn, err = grpc.Dial(g.Address, grpc.WithInsecure()) + g.opts = opts + g.Conn, err = grpc.Dial(g.Address, opts...) if err != nil { return fmt.Errorf("Connecting GRPC Client: %v", err) @@ -67,7 +69,7 @@ func (g *GrpcClient) Reconnect(url string) error { if len(url) > 0 { g.Address = url } - g.Start() + g.Start(g.opts...) return nil }