Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proxy support #35

Open
valsha opened this issue Mar 11, 2023 · 0 comments
Open

proxy support #35

valsha opened this issue Mar 11, 2023 · 0 comments

Comments

@valsha
Copy link

valsha commented Mar 11, 2023

import (
    "context"
    "net"
    "net/http"
    "time"
)

func main() {
    // create a SOCKS5 proxy dialer
    dialer, err := proxy.SOCKS5("tcp", "localhost:1080", nil, proxy.Direct)
    if err != nil {
        // handle error
    }

    // create a transport that uses the SOCKS5 proxy dialer
    transport := &http.Transport{
        DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
            return dialer.Dial(network, addr)
        },
    }

    // create an http.Client that uses the custom transport
    httpClient := &http.Client{
        Timeout:   10 * time.Second,
        Transport: transport,
    }

    // use the httpClient to make requests
    resp, err := httpClient.Get("https://example.com")
    if err != nil {
        // handle error
    }
    defer resp.Body.Close()

    // read the response body
    // ...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant