A SOCKS (SOCKS4, SOCKS4A and SOCKS5) Proxy Package for Go
Go
Switch branches/tags
Nothing to show
Latest commit fa8c792 Jun 17, 2016 @h12w h12w add an example
Permalink
Failed to load latest commit information.
spec Add spec of SOCKS protocols. Aug 1, 2012
.gitignore Initial commit Jul 31, 2012
LICENSE Add the license file. Aug 1, 2012
README.md add an example Jun 17, 2016
socks.go Fix formatting with go fmt. Feb 15, 2016

README.md

SOCKS

GoDoc

SOCKS is a SOCKS4, SOCKS4A and SOCKS5 proxy package for Go.

Quick Start

Get the package

go get -u "h12.me/socks"

Import the package

import "h12.me/socks"

Create a SOCKS proxy dialing function

dialSocksProxy := socks.DialSocksProxy(socks.SOCKS5, "127.0.0.1:1080")
tr := &http.Transport{Dial: dialSocksProxy}
httpClient := &http.Client{Transport: tr}

Example

package main

import (
	"fmt"
	"io/ioutil"
	"log"
	"net/http"

	"h12.me/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))
}

Alternatives

http://godoc.org/golang.org/x/net/proxy