Home

Awesome

MultiProxy Client for Go

Go Report Card codecov Go Test GoDoc License: MIT

Overview

MultiProxy Client is a robust Go library designed to manage multiple HTTP/HTTPS and SOCKS5 proxies efficiently. It provides a fault-tolerant and load-balanced approach to making HTTP requests through a pool of proxies, with features like automatic retries, backoff mechanisms, and proxy rotation.

Features

Installation

To use MultiProxy Client in your Go project, you can install it using go get:

go get github.com/presbrey/go-multiproxy

Replace yourusername with the actual GitHub username or organization where this project is hosted.

Usage

Here's a basic example of how to use the MultiProxy Client:

package main

import (
    "fmt"
    "net/http"
    "time"
    
    "github.com/presbrey/go-multiproxy"
)

func main() {
    config := multiproxy.Config{
        Proxies: []multiproxy.Proxy{
            {
                URL:  &url.URL{Scheme: "http", Host: "proxy1.example.com:8080"},
                Auth: &multiproxy.ProxyAuth{Username: "user1", Password: "pass1"},
            },
            {
                URL:  &url.URL{Scheme: "socks5", Host: "proxy2.example.com:1080"},
                Auth: &multiproxy.ProxyAuth{Username: "user2", Password: "pass2"},
            },
        },
        CookieTimeout:    10 * time.Minute,
        CookieOptions:    &cookiejar.Options{PublicSuffixList: publicsuffix.List},
        DialTimeout:      30 * time.Second,
        RequestTimeout:   1 * time.Minute,
        RetryAttempts:    3,
        RetryDelay:       5 * time.Second,
        ProxyRotateCount: 10,
    }

    client, err := multiproxy.NewClient(config)
    if err != nil {
        panic(err)
    }

    resp, err := client.Get("https://example.com")
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    fmt.Printf("Response status: %s\n", resp.Status)
}

Configuration

The Config struct allows you to customize the behavior of the MultiProxy Client:

Using the RoundTripper

The MultiProxy Client provides a RoundTripper() method that returns an http.RoundTripper. This allows you to use the multi-proxy functionality with any http.Client. Here's an example:

config := multiproxy.Config{
    // ... your config here ...
}

client, err := multiproxy.NewClient(config)
if err != nil {
    // handle error
}

httpClient := &http.Client{
    Transport: client.RoundTripper(),
}

// Now use httpClient for your requests
resp, err := httpClient.Get("https://example.com")

This is particularly useful when you need to use the multi-proxy functionality with libraries or APIs that accept an http.Client.

Testing

The project includes comprehensive test suites:

To run the tests, use the following command:

go test ./...

Contributing

Contributions to the MultiProxy Client are welcome! Please feel free to submit issues, fork the repository and send pull requests.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Disclaimer

This software is provided as-is, and users should be aware of the legal and ethical considerations when using proxy servers. Always ensure you have the right to use the proxy servers you configure with this client.