gowebshareproxy

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 9, 2019 License: MIT Imports: 8 Imported by: 0

README

gowebshareproxy

GoDoc

Simple SDK to make requests through proxy.webshare.io.

Make proxied requests by specifying the proxy you will go through or choose a random proxy if given a list.

Basic Usage
  1. Sign up for free here.
  2. Go to proxy > list and make a note of a proxy address, username and password. You can also download the proxy list as a colon delimited text file if you want to do some stuff programatically.
  3. Do the following (add your own error checking):
package main

import (
    "net/http"
    "net/url"
    
    "github.com/j7mbo/gowebshareproxy"
)

func main() {
    // Input your proxy configuration here.
    proxyUser := "<YOUR-PROXY-USERNAME>"
    proxyPass := "<YOUR-PROXY-PASSWORD>"
    proxyUri, _ := url.Parse("<YOUR-PROXY-HOST>:<YOUR-PROXY-PORT>")
    
    // Url to make proxied request to.
    uri, _ := url.Parse("http://httpbin.org/get")
    
    // Create your request as normal.
    request, _ := http.NewRequest("GET", uri.String(), nil)
    
    // Initialise gowebshareproxy.
    proxy := gowebshareproxy.New(&http.Client{})

    // Make the proxied request.
    res, err := proxy.Request(request, proxyUri, proxyUser, proxyPass)
}
Advanced Usage

You can use Proxy.RequestWithRandomProxy to choose a random proxy to perform a request through. From this call you get back the response, any error as well as the chosen proxy url so you know which proxy you went through.

On the proxy > list page you will find a button where you can download your proxy list. It will have the following format:

x.x.x.x:80:username-123:password1
x.x.x.x:80:username-234:password2
x.x.x.x:80:username-345:password3

Read in and parse this file into an []string, and then use Proxy.RequestWithRandomProxy:

file, _ := os.Open(path)
defer file.Close()

var lines []string

scanner := bufio.NewScanner(file)

for scanner.Scan() {
    lines = append(lines, scanner.Text())
}

proxy := proxy.NewWithList(&http.Client{}, lines)

request, _ := http.NewRequest("GET", "http://httpbin.org/get", nil)

chosenProxy, res, err := proxy.RequestWithRandomProxy(request)

Note that if you try and call Proxy.RequestWithRandomProxy without having initialised via NewWithList you will get an error.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Proxy

type Proxy interface {
	// Request decorates http.Client.Do() by adding the given proxy configuration to the request.
	Request(request http.Request, proxyURL url.URL, proxyUser string, proxyPassword string) (*http.Response, error)
	// RequestWithRandomProxy chooses a random proxy to make the given request through and returns both the response /
	// error combination and the chosen proxy.
	RequestWithRandomProxy(request http.Request) (proxyURL *url.URL, response *http.Response, err error)
}

Proxy is used to perform a proxied request via gowebshareproxy.

func New

func New(client http.Client) Proxy

NewProxy returns a new Proxy with an (optionally pre-configured) http client.

func NewWithList

func NewWithList(client http.Client, proxyList []string) Proxy

NewWithList returns a new Proxy with an (optionally pre-configured) http client and a list of proxies, which you can download directly from the [webshare proxy list page](https://proxy.webshare.io/proxy/list). You can then call Proxy.RequestWithRandomProxy() to have a proxy randomly chosen from this list for the given request.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL