replace grpc.WithDialer which is deprecated

This commit is contained in:
danielqsj
2019-10-25 16:30:41 +08:00
parent 2914ba8e04
commit 19fe9f8d94
12 changed files with 28 additions and 31 deletions

View File

@@ -19,13 +19,13 @@ limitations under the License.
package util
import (
"context"
"fmt"
"io/ioutil"
"net"
"net/url"
"os"
"path/filepath"
"time"
"golang.org/x/sys/unix"
"k8s.io/klog"
@@ -78,8 +78,8 @@ func CreateListener(endpoint string) (net.Listener, error) {
return l, nil
}
// GetAddressAndDialer returns the address parsed from the given endpoint and a dialer.
func GetAddressAndDialer(endpoint string) (string, func(addr string, timeout time.Duration) (net.Conn, error), error) {
// GetAddressAndDialer returns the address parsed from the given endpoint and a context dialer.
func GetAddressAndDialer(endpoint string) (string, func(ctx context.Context, addr string) (net.Conn, error), error) {
protocol, addr, err := parseEndpointWithFallbackProtocol(endpoint, unixProtocol)
if err != nil {
return "", nil, err
@@ -91,8 +91,8 @@ func GetAddressAndDialer(endpoint string) (string, func(addr string, timeout tim
return addr, dial, nil
}
func dial(addr string, timeout time.Duration) (net.Conn, error) {
return net.DialTimeout(unixProtocol, addr, timeout)
func dial(ctx context.Context, addr string) (net.Conn, error) {
return (&net.Dialer{}).DialContext(ctx, unixProtocol, addr)
}
func parseEndpointWithFallbackProtocol(endpoint string, fallbackProtocol string) (protocol string, addr string, err error) {