Go library providing an HTTP RoundTripper with automatic proxy server pool management.
- Automatic proxy downloading from known sources
- Proxy validation through google.com requests
- Proxy rotation for each request
- Proxy statistics and automatic Bad Pool placement
- HTTP and SOCKS5 proxy support
- Automatic pool replenishment when needed
package main
import (
"fmt"
"log"
"time"
"github.com/aredoff/proxygun"
)
func main() {
config := proxygun.DefaultConfig()
config.PoolSize = 20
config.MaxRetries = 5
client := proxygun.NewProxyClient(config)
defer client.Close()
// Wait for proxy loading
time.Sleep(5 * time.Second)
resp, err := client.Get("https://httpbin.org/ip")
if err != nil {
log.Printf("Error: %v", err)
return
}
defer resp.Body.Close()
fmt.Printf("Status: %s\n", resp.Status)
fmt.Printf("Stats: %+v\n", client.Stats())
}package main
import (
"net/http"
"time"
"github.com/aredoff/proxygun"
)
func main() {
config := proxygun.DefaultConfig()
// Create ProxyRoundTripper
rt := proxygun.NewProxyRoundTripper(config)
defer rt.Close()
// Use with custom http.Client
client := &http.Client{
Transport: rt,
Timeout: 45 * time.Second,
}
resp, err := client.Get("https://httpbin.org/ip")
// Handle response...
}type Config struct {
PoolSize int // Proxy pool size (default 50)
MaxRetries int // Maximum retry attempts (default 3)
RefreshInterval time.Duration // Proxy refresh interval (default 10 seconds)
ValidationWorkers int // Number of validation workers (default 30, max 50)
BadProxyMaxAge time.Duration // Bad proxy retention time (default 24 hours)
FallbackTransport http.RoundTripper // Fallback transport when all proxies fail (default http.DefaultTransport)
Logger zerolog.Logger // Logger for internal messages (default console logger)
}By default, if all proxies fail, the library will use http.DefaultTransport for direct connections. You can customize this behavior:
config := proxygun.DefaultConfig()
// Use custom fallback transport
config.FallbackTransport = &http.Transport{
MaxIdleConns: 10,
IdleConnTimeout: 30 * time.Second,
DisableCompression: true,
}
// Disable fallback (fail if no proxies work)
config.FallbackTransport = nilThe library uses zerolog for structured logging. By default, it outputs to stderr with a console-friendly format:
config := proxygun.DefaultConfig()
// Use custom logger
config.Logger = zerolog.New(os.Stdout).With().Timestamp().Logger()
// Disable logging
config.Logger = zerolog.Nop()
// JSON logging
config.Logger = zerolog.New(os.Stdout).With().Timestamp().Logger()The library consists of the following components:
client.go- main HTTP RoundTripper with proxy rotationinternal/proxy/- structures for proxy representation and statisticsinternal/pool/- proxy pool management (main, free, bad)internal/parser/- parsers for proxy websitesinternal/validator/- proxy validator through test requests
NewProxyRoundTripper(config *Config) *ProxyRoundTripper- Creates a new RoundTripperRoundTrip(req *http.Request) (*http.Response, error)- Implements http.RoundTripper interfaceStats() map[string]interface{}- Returns proxy pool statisticsClose() error- Stops background workers
NewProxyClient(config *Config) *ProxyClient- Creates a wrapped http.Client- All standard http.Client methods (Get, Post, Do, etc.)
Stats() map[string]interface{}- Returns proxy pool statisticsClose() error- Stops background workers
NewClient(config *Config) *http.Client- Returns standard http.Client with ProxyRoundTripper
- https://www.sslproxies.org
- https://www.us-proxy.org
- https://free-proxy-list.net/uk-proxy.html
- https://free-proxy-list.net
MIT