Connect net / http unix to a domain

I am having trouble connecting to my server that is listening on a Unix Domain Socket.

Package

Go net/httpdoes not seem to be able to use socket paths to connect to the target.

Is there a good alternative without having to create my own implementation of the HTTP protocol with net?


I found many solutions like these , but they are unsuitable

I tried:

_, err := http.Get("unix:///var/run/docker.sock")(change unixto path/ socket. He always complains about an unsupported protocol

+4
source share
2 answers

RoundTripper unix.

- http unix sockets .

init script -H tcp://127.0.0.1:xxxx, :

/usr/bin/docker -H tcp://127.0.0.1:9020

:

func fakeDial(proto, addr string) (conn net.Conn, err error) {
    return net.Dial("unix", sock)
}

tr := &http.Transport{
    Dial: fakeDial,
}
client := &http.Client{Transport: tr}
resp, err := client.Get("http://d/test")

playground

, client.Get/.Post URL (http://xxxx.xxx/path not unix://...), , .

+19

, , , . httpunix, . , URL-, HTTP + Unix://-/...... .

+1

All Articles