mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 08:14:18 -04:00
add support unix socket for GRPC (#5943)
This commit is contained in:
@@ -33,6 +33,14 @@ func HostPortOrFile(s ...string) ([]string, error) {
|
||||
var servers []string
|
||||
for _, h := range s {
|
||||
trans, host := Transport(h)
|
||||
if len(host) == 0 {
|
||||
return servers, fmt.Errorf("invalid address: %q", h)
|
||||
}
|
||||
|
||||
if trans == transport.UNIX {
|
||||
servers = append(servers, trans+"://"+host)
|
||||
continue
|
||||
}
|
||||
|
||||
addr, _, err := net.SplitHostPort(host)
|
||||
|
||||
|
||||
@@ -58,6 +58,16 @@ func TestHostPortOrFile(t *testing.T) {
|
||||
"",
|
||||
true,
|
||||
},
|
||||
{
|
||||
"unix:///var/run/g.sock",
|
||||
"unix:///var/run/g.sock",
|
||||
false,
|
||||
},
|
||||
{
|
||||
"unix://",
|
||||
"",
|
||||
true,
|
||||
},
|
||||
}
|
||||
|
||||
err := os.WriteFile("resolv.conf", []byte("nameserver 127.0.0.1\n"), 0600)
|
||||
|
||||
@@ -27,6 +27,9 @@ func Transport(s string) (trans string, addr string) {
|
||||
s = s[len(transport.HTTPS+"://"):]
|
||||
|
||||
return transport.HTTPS, s
|
||||
case strings.HasPrefix(s, transport.UNIX+"://"):
|
||||
s = s[len(transport.UNIX+"://"):]
|
||||
return transport.UNIX, s
|
||||
}
|
||||
|
||||
return transport.DNS, s
|
||||
|
||||
@@ -6,6 +6,7 @@ const (
|
||||
TLS = "tls"
|
||||
GRPC = "grpc"
|
||||
HTTPS = "https"
|
||||
UNIX = "unix"
|
||||
)
|
||||
|
||||
// Port numbers for the various transports.
|
||||
|
||||
Reference in New Issue
Block a user