Skip to content

Commit

Permalink
Merge pull request #13 from fbsobreira/grpc-dial-options
Browse files Browse the repository at this point in the history
add dial option on grpc start
  • Loading branch information
fbsobreira authored Mar 16, 2021
2 parents 7ad5b92 + 092f1f0 commit 8cb47d5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion cmd/subcommands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
}

Expand Down
8 changes: 5 additions & 3 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type GrpcClient struct {
Conn *grpc.ClientConn
Client api.WalletClient
grpcTimeout time.Duration
opts []grpc.DialOption
}

// NewGrpcClient create grpc controller
Expand All @@ -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)
Expand All @@ -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
}

Expand Down

0 comments on commit 8cb47d5

Please sign in to comment.