This commit is contained in:
Adam Ierymenko 2019-09-24 16:44:29 -07:00
commit e5bd230fb0
No known key found for this signature in database
GPG key ID: C8877CF2D7A5D7F3
15 changed files with 197 additions and 42 deletions

View file

@ -16,9 +16,12 @@
package zerotier
import (
"context"
"net"
"net/http"
"os"
"path"
"time"
)
func createNamedSocketListener(basePath, name string) (net.Listener, error) {
@ -26,3 +29,17 @@ func createNamedSocketListener(basePath, name string) (net.Listener, error) {
os.Remove(apiSockPath)
return net.Listen("unix", apiSockPath)
}
func createNamedSocketHTTPClient(basePath, name string) (*http.Client, error) {
apiSockPath := path.Join(basePath, name)
return &http.Client{
Timeout: 10 * time.Second,
Transport: &http.Transport{
DialContext: func(_ context.Context, _, _ string) (net.Conn, error) {
return net.Dial("unix", apiSockPath)
},
DisableKeepAlives: true,
DisableCompression: true,
},
}, nil
}