Skip to content

Simple proxy manager for Go. Supports HTTP(s)/SOCK4(a)/SOCKS5.

Notifications You must be signed in to change notification settings

multimikael/proxy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

proxy

GoDoc

proxy is a simple proxy manager library. It supports HTTP(s)/SOCK4(a)/SOCKS5.

Installation

proxy can be installed using go get:

go get github.com/multimikael/proxy

Example

This is a simple example of using the proxy manager and ClientFromProxy. This example reads HTTP proxies from a text file "proxies.txt". It gets a proxy from the manager and passes it to ClientFromProxy to get an HTTP client. Finally it makes a GET request through the proxy. This a cut from the whoami example in the examples folder.

package main

import (
	"fmt"
	"io/ioutil"

	"github.com/multimikael/proxy"
)

func main() {
	// Create proxy manager and read from proxies from file "proxies.txt"
	pm := proxy.NewManager()
	pm.AppendProxiesFromFile(proxy.HTTP, "proxies.txt")

	// Get a random alive proxy from the proxy manager
	p, err := pm.Get()
	if err != nil {
		panic(err)
	}

	// Get an HTTP client with the proxy, and timeout after 10 seconds
	client, err := proxy.ClientFromProxy(p, 10)
	if err != nil {
		panic(err)
	}

	// Make a GET request through the proxy
	resp, err := client.Get("https://www.cloudflare.com/cdn-cgi/trace")
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()
	body, _ := ioutil.ReadAll(resp.Body)
	fmt.Println(string(body))
}

About

Simple proxy manager for Go. Supports HTTP(s)/SOCK4(a)/SOCKS5.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages