blob: 52d7f8617f7af3d6abf419c89b684142304b9b46 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
package torgo
import (
"net/http"
"net/url"
"golang.org/x/net/proxy"
)
// NewClient return new HTTP client that uses a Tor SOCKS proxy.
// `addr` is the host:port address of SOCKS proxy (usually "127.0.0.1:9050")
func NewClient(addr string) (*http.Client, error) {
u, err := url.Parse("socks5://" + addr)
if err != nil {
return nil, err
}
d, err := proxy.FromURL(u, proxy.Direct)
if err != nil {
return nil, err
}
t := &http.Transport{Dial: d.Dial}
return &http.Client{Transport: t}, nil
}
|