proxypool

package module
v0.0.0-...-3026b35 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2021 License: Unlicense Imports: 13 Imported by: 0

README

proxypool GoDoc Go Report Card

This package distributes requests through a pool of proxies, acting as a proxy gateway that supports CONNECT requests. Proxy rotation spreads out usage as much as possible to avoid IP bans or restrictions. The gateway only accepts proxy urls with the https scheme.

Installation

go get -u github.com/aidenesco/proxypool

Usage

Loading proxies

import "github.com/aidenesco/proxypool"

func main() {
    pool := proxypool.NewPool()

    proxyUrl, _ := url.Parse("https://username:password@host:port")

    _ = pool.AddProxy(proxyUrl)

Server

import "github.com/aidenesco/proxypool"

func main() {
    pool := proxypool.NewPool()
    //Load pool with your proxies

    server := &http.Server{
        Addr:         ":443",
        Handler:      http.HandlerFunc(pool.Serve),
        TLSNextProto: make(map[string]func(*http.Server, *tls.Conn, http.Handler)),
    }

    log.Fatal(server.ListenAndServeTLS("your-cert", "your-key"))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

Pool holds a ring of proxies used to distribute requests

func NewPool

func NewPool() *Pool

NewPool returns a new, empty pool

func (*Pool) AddProxy

func (p *Pool) AddProxy(url *url.URL, options ...ProxyOption) (err error)

AddProxy adds a proxy to the ring, with options applied

func (*Pool) Serve

func (p *Pool) Serve(w http.ResponseWriter, r *http.Request)

Serve is an http handler to serve as a gateway proxy. Only accepts CONNECT requests

type ProxyOption

type ProxyOption func(*proxy) error

ProxyOption is an option that modifies a Proxy

func WithBetweenUse

func WithBetweenUse(dur time.Duration) ProxyOption

WithBetweenUse sets a duration for a proxy to wait before it's used again on the same host

Jump to

Keyboard shortcuts

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