Matt Baer 5be269b4e6 | 5 年之前 | |
---|---|---|
spec | 11 年之前 | |
.gitignore | 11 年之前 | |
LICENSE | 11 年之前 | |
README.md | 5 年之前 | |
socks.go | 5 年之前 |
SOCKS is a SOCKS4, SOCKS4A and SOCKS5 proxy package for Go, forked from h12w/socks and patched so it’s go get
able.
go get -u "code.as/core/socks"
import "code.as/core/socks"
dialSocksProxy := socks.DialSocksProxy(socks.SOCKS5, "127.0.0.1:1080")
tr := &http.Transport{Dial: dialSocksProxy}
httpClient := &http.Client{Transport: tr}
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"code.as/core/socks"
)
func main() {
dialSocksProxy := socks.DialSocksProxy(socks.SOCKS5, "127.0.0.1:1080")
tr := &http.Transport{Dial: dialSocksProxy}
httpClient := &http.Client{Transport: tr}
resp, err := httpClient.Get("http://www.google.com")
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
log.Fatal(resp.StatusCode)
}
buf, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(buf))
}