This repo contains Dialers http connect and https for golang.org/x/net/proxy
import the connect package first and follow the below examples
Note: for http requests (its preferable to HTTP_PROXY and HTTPS_PROXY env vars in this case)
uri, err := url.Parse("http://proxy_url:proxy_port")
if err != nil {
panic(err)
}
dialer, err := proxy.FromURL(uri, proxy.Direct)
if err != nil {
panic(err)
}
client := http.Client{
Transport: &http.Transport{
Proxy: nil,
DialContext: dialer.Dial,
},
}
In this case we need to make use of the grpc.WithContextDialer DialOption
grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) {
uri, err := url.Parse(httpproxy.FromEnvironment().HTTPProxy)
if err != nil {
return nil, err
}
dialer, err := proxy.FromURL(uri, proxy.Direct)
if err != nil {
return nil, err
}
return dialer.Dial("tcp", addr)
}),
import the https package and follow the below example
uri, err := url.Parse(httpproxy.FromEnvironment().HTTPProxy)
if err != nil {
return nil, err
}
dialer, err := proxy.FromURL(uri, https.HTTPSDialer)
if err != nil {
return nil, err
}