Skip to content

Commit

Permalink
grpc: Add grpc.DialContext
Browse files Browse the repository at this point in the history
  • Loading branch information
daemonfire300 committed Sep 13, 2021
1 parent a432747 commit 54490e1
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions grpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,20 @@ import (
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
)

func Dial(address string) (*grpc.ClientConn, error) {
func DialContext(ctx context.Context, addr string) (*grpc.ClientConn, error) {
return dialCtx(ctx, addr)
}

func Dial(addr string) (*grpc.ClientConn, error) {
return dialCtx(context.Background(), addr)
}

func dialCtx(ctx context.Context, addr string) (*grpc.ClientConn, error) {
var conn *grpc.ClientConn
opts := []grpc_retry.CallOption{
grpc_retry.WithBackoff(grpc_retry.BackoffLinear(100 * time.Millisecond)),
}
conn, err := grpc.Dial(address, grpc.WithInsecure(),
conn, err := grpc.DialContext(ctx, addr, grpc.WithInsecure(),
grpc.WithChainStreamInterceptor(
grpc_opentracing.StreamClientInterceptor(),
grpc_prometheus.StreamClientInterceptor,
Expand Down

0 comments on commit 54490e1

Please sign in to comment.