| // GetProxyEnv allows access to the uppercase and the lowercase forms of |
| // proxy-related variables. See the Go specification for details on these |
| // variables. https://golang.org/pkg/net/http/ |
| func GetProxyEnv(key string) string { |
| proxyValue := os.Getenv(strings.ToUpper(key)) |
| return os.Getenv(strings.ToLower(key)) |
| // DialerFromEnvironment takes in a "direct" *net.Dialer and returns a |
| // proxy.Dialer which will route the connections through the proxy using the |
| func DialerFromEnvironment(direct *net.Dialer) (proxy.Dialer, error) { |
| allProxy := GetProxyEnv("all_proxy") |
| proxyURL, err := url.Parse(allProxy) |
| proxyFromURL, err := proxy.FromURL(proxyURL, direct) |
| noProxy := GetProxyEnv("no_proxy") |
| perHost := proxy.NewPerHost(proxyFromURL, direct) |
| perHost.AddFromString(noProxy) |