Documentation ¶
Overview ¶
Package ieproxy is a utility to retrieve the proxy parameters (especially of Internet Explorer on windows)
On windows, it gathers the parameters from the registry (regedit), while it uses env variable on other platforms
Example ¶
package main import ( "fmt" "net/http" "os" ) func init() { OverrideEnvWithStaticProxy() http.DefaultTransport.(*http.Transport).Proxy = http.ProxyFromEnvironment } func main() { fmt.Println("== Proxy configuration ==") for _, name := range []string{"http_proxy", "https_proxy", "no_proxy"} { fmt.Println(name + ": " + os.Getenv(name)) } fmt.Println("== Proxy test ==") req, err := http.NewRequest("GET", "https://golang.org/", nil) if err != nil { panic(err) } url, err := http.DefaultTransport.(*http.Transport).Proxy(req) if err != nil { panic(err) } if url != nil { fmt.Println("PROXY " + url.String()) } else { fmt.Println("DIRECT") } // Coming output: == Proxy configuration == // http_proxy: ... }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func OverrideEnvWithStaticProxy ¶
func OverrideEnvWithStaticProxy()
OverrideEnvWithStaticProxy writes new values to the `http_proxy`, `https_proxy` and `no_proxy` environment variables. The values are taken from the Windows Regedit (should be called in `init()` function - see example)
func StringFromUTF16Ptr ¶
StringFromUTF16Ptr converts a *uint16 C string to a Go String
Types ¶
type AutomaticProxyConf ¶
type AutomaticProxyConf struct { // Is the proxy active? Active bool // URL of the .pac file URL string }
AutomaticProxyConf contains the configuration for automatic proxy
func (*AutomaticProxyConf) FindProxyForURL ¶
func (apc *AutomaticProxyConf) FindProxyForURL(URL string) string
FindProxyForURL computes the proxy for a given URL according to the pac file
type ProxyConf ¶
type ProxyConf struct { Static StaticProxyConf // static configuration Automatic AutomaticProxyConf // automatic configuration }
ProxyConf gathers the configuration for proxy
type StaticProxyConf ¶
type StaticProxyConf struct { // Is the proxy active? Active bool // Proxy address for each scheme (http, https) // "" (empty string) is the fallback proxy Protocols map[string]string // Addresses not to be browsed via the proxy (comma-separated, linux-like) NoProxy string }
StaticProxyConf contains the configuration for static proxy