clientconn: add support for unix network in DialContext. (#1883)

This commit is contained in:
Sam Batschelet
2018-04-09 14:12:34 -04:00
committed by Menghan Li
parent 30fb59a430
commit 7316918402
3 changed files with 58 additions and 1 deletions

View File

@ -26,6 +26,7 @@ import (
"io"
"io/ioutil"
"math"
"net/url"
"strings"
"sync"
"time"
@ -672,6 +673,40 @@ func setCallInfoCodec(c *callInfo) error {
return nil
}
// parseDialTarget returns the network and address to pass to dialer
func parseDialTarget(target string) (net string, addr string) {
net = "tcp"
m1 := strings.Index(target, ":")
m2 := strings.Index(target, ":/")
// handle unix:addr which will fail with url.Parse
if m1 >= 0 && m2 < 0 {
if n := target[0:m1]; n == "unix" {
net = n
addr = target[m1+1:]
return net, addr
}
}
if m2 >= 0 {
t, err := url.Parse(target)
if err != nil {
return net, target
}
scheme := t.Scheme
addr = t.Path
if scheme == "unix" {
net = scheme
if addr == "" {
addr = t.Host
}
return net, addr
}
}
return net, target
}
// The SupportPackageIsVersion variables are referenced from generated protocol
// buffer files to ensure compatibility with the gRPC version used. The latest
// support package version is 5.