pkg/transport: support listeners on unix sockets

Given unix://<socketname>, NewListener will listen on unix socket <socketname>.
This is useful when binding to tcp ports is undesirable (e.g., testing).
This commit is contained in:
Anthony Romano 2016-01-06 12:09:05 -08:00
parent eab052d5c4
commit f2df87f3e4
2 changed files with 15 additions and 1 deletions

View File

@ -26,7 +26,13 @@ import (
)
func NewListener(addr string, scheme string, info TLSInfo) (net.Listener, error) {
l, err := net.Listen("tcp", addr)
nettype := "tcp"
if scheme == "unix" {
// unix sockets via unix://laddr
nettype = scheme
}
l, err := net.Listen(nettype, addr)
if err != nil {
return nil, err
}

View File

@ -241,3 +241,11 @@ func TestTLSInfoConfigFuncs(t *testing.T) {
}
}
}
func TestNewListenerUnixSocket(t *testing.T) {
l, err := NewListener("testsocket", "unix", TLSInfo{})
if err != nil {
t.Errorf("error listening on unix socket (%v)", err)
}
l.Close()
}