Use grpc.NewClient instead of deprecated ones
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
This commit is contained in:
parent
a5be629936
commit
63b4688175
@ -115,17 +115,14 @@ func New(address string, opts ...Opt) (*Client, error) {
|
||||
}
|
||||
if address != "" {
|
||||
backoffConfig := backoff.DefaultConfig
|
||||
backoffConfig.MaxDelay = 3 * time.Second
|
||||
backoffConfig.MaxDelay = copts.timeout
|
||||
connParams := grpc.ConnectParams{
|
||||
Backoff: backoffConfig,
|
||||
}
|
||||
gopts := []grpc.DialOption{
|
||||
grpc.WithBlock(),
|
||||
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
||||
grpc.FailOnNonTempDialError(true),
|
||||
grpc.WithConnectParams(connParams),
|
||||
grpc.WithContextDialer(dialer.ContextDialer),
|
||||
grpc.WithReturnConnectionError(),
|
||||
}
|
||||
if len(copts.dialOptions) > 0 {
|
||||
gopts = copts.dialOptions
|
||||
@ -143,9 +140,7 @@ func New(address string, opts ...Opt) (*Client, error) {
|
||||
}
|
||||
|
||||
connector := func() (*grpc.ClientConn, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), copts.timeout)
|
||||
defer cancel()
|
||||
conn, err := grpc.DialContext(ctx, dialer.DialAddress(address), gopts...)
|
||||
conn, err := grpc.NewClient(dialer.DialAddress(address), gopts...)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to dial %q: %w", address, err)
|
||||
}
|
||||
|
@ -100,15 +100,11 @@ func connect(address string, d func(context.Context, string) (net.Conn, error))
|
||||
Backoff: backoffConfig,
|
||||
}
|
||||
gopts := []grpc.DialOption{
|
||||
grpc.WithBlock(),
|
||||
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
||||
grpc.WithContextDialer(d),
|
||||
grpc.FailOnNonTempDialError(true),
|
||||
grpc.WithConnectParams(connParams),
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
||||
defer cancel()
|
||||
conn, err := grpc.DialContext(ctx, dialer.DialAddress(address), gopts...)
|
||||
conn, err := grpc.NewClient(dialer.DialAddress(address), gopts...)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to dial %q: %w", address, err)
|
||||
}
|
||||
|
@ -587,7 +587,7 @@ func (pc *proxyClients) getClient(address string) (*grpc.ClientConn, error) {
|
||||
grpc.WithDefaultCallOptions(grpc.MaxCallSendMsgSize(defaults.DefaultMaxSendMsgSize)),
|
||||
}
|
||||
|
||||
conn, err := grpc.Dial(dialer.DialAddress(address), gopts...)
|
||||
conn, err := grpc.NewClient(dialer.DialAddress(address), gopts...)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to dial %q: %w", address, err)
|
||||
}
|
||||
|
@ -275,14 +275,10 @@ func makeConnection(ctx context.Context, id string, params client.BootstrapParam
|
||||
|
||||
return ttrpc.NewClient(conn, ttrpc.WithOnClose(onClose)), nil
|
||||
case "grpc":
|
||||
ctx, cancel := context.WithTimeout(ctx, time.Second*100)
|
||||
defer cancel()
|
||||
|
||||
gopts := []grpc.DialOption{
|
||||
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
||||
grpc.WithBlock(),
|
||||
}
|
||||
return grpcDialContext(ctx, params.Address, onClose, gopts...)
|
||||
return grpcDialContext(params.Address, onClose, gopts...)
|
||||
default:
|
||||
return nil, fmt.Errorf("unexpected protocol: %q", params.Protocol)
|
||||
}
|
||||
@ -292,7 +288,6 @@ func makeConnection(ctx context.Context, id string, params client.BootstrapParam
|
||||
// so we can have something similar to ttrpc.WithOnClose to have
|
||||
// a callback run when the connection is severed or explicitly closed.
|
||||
func grpcDialContext(
|
||||
ctx context.Context,
|
||||
address string,
|
||||
onClose func(),
|
||||
gopts ...grpc.DialOption,
|
||||
@ -316,7 +311,7 @@ func grpcDialContext(
|
||||
conn.Close()
|
||||
|
||||
target := dialer.DialAddress(address)
|
||||
client, err := grpc.DialContext(ctx, target, gopts...)
|
||||
client, err := grpc.NewClient(target, gopts...)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create GRPC connection: %w", err)
|
||||
}
|
||||
|
@ -245,14 +245,8 @@ func openStream(ctx context.Context, urlStr string) (streamingapi.Stream, error)
|
||||
return stream, nil
|
||||
|
||||
case "grpc":
|
||||
ctx, cancel := context.WithTimeout(ctx, time.Second*100)
|
||||
defer cancel()
|
||||
|
||||
gopts := []grpc.DialOption{
|
||||
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
||||
grpc.WithBlock(),
|
||||
}
|
||||
conn, err := grpc.DialContext(ctx, realAddress, gopts...)
|
||||
gopts := []grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials())}
|
||||
conn, err := grpc.NewClient(realAddress, gopts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user