This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// TorProxy initializes and returns a TOR SOCKS proxy function for use in a Transport | |
func TorProxy() func(*http.Request) (*url.URL, error) { | |
// A source of uniformly-distributed pseudo-random | |
rand.Seed(time.Now().UnixNano()) | |
// Pseudo-random int value | |
num := rand.Intn(0x7fffffff-10000) + 10000 | |
// Tor listens for SOCKS connections on localhost port 9050 | |
base := "socks5://%d:x@127.0.0.1:9050" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SmartProxy initializes and returns a proxy function for use in a Transport | |
func SmartProxy() func(*http.Request) (*url.URL, error) { | |
// base url | |
base := "https://%s:%s@%s" | |
// fill credentials into url | |
rawUrl := fmt.Sprintf(base, <YOUR_SMARTPROXY_USERNAME>, <YOUR_SMARTPROXY_PASSWORD>, "gate.dc.smartproxy.com:20000") | |
// parse proxy url | |
proxyUrl, err := url.Parse(rawUrl) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Tor represents an HTTP Client over the Tor network | |
type Tor struct { | |
MaxTimeout time.Duration // Max Timeout | |
MaxIdleConnections int // Max Idle Connections | |
Transport *http.Transport // Custom Transport | |
once sync.Once // sync so we only set up 1 client | |
netClient *http.Client // http client | |
} | |
// New creates an instance of a Tor Client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main() { | |
// configuration for tor client | |
tor := ht.Tor { | |
MaxTimeout: 20 * time.Second, | |
MaxIdleConnections: 10, | |
} | |
// new instance of tor client | |
torClient := tor.New() |