Skip to content

Commit

Permalink
add an example
Browse files Browse the repository at this point in the history
  • Loading branch information
Hǎiliàng Wáng committed Jun 17, 2016
1 parent 6e16ba9 commit fa8c792
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,39 @@ SOCKS is a SOCKS4, SOCKS4A and SOCKS5 proxy package for Go.
tr := &http.Transport{Dial: dialSocksProxy}
httpClient := &http.Client{Transport: tr}

## Example

```go
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

0 comments on commit fa8c792

Please sign in to comment.