To harness the full potential of Go's development capabilities, it's essential to configure its command to utilize a proxy. This article delves into how to achieve this configuration.
Go programs leverage the http_proxy and no_proxy environment variables to establish proxy settings. However, these variables alone are insufficient, as Go relies on source control managers (SCMs) for code retrieval. Hence, you'll need to configure the HTTP proxy for these SCMs as well.
For Mercurial, refer to these instructions. For Git, consult this guide.
The http_proxy variable defines the proxy server settings, which can include a custom format like http://user:password@host:port/. The user, password, and port components are optional.
Conversely, the no_proxy variable specifies a comma-separated list of servers that should bypass the proxy connection. Its format can resemble foo.com,bar.net:4000.
Modify your bash_profile to incorporate these environment variables. Alternatively, you can limit their use to Go commands by invoking them explicitly, as seen in:
$ http_proxy=127.0.0.1:8080 go get code.google.com/p/go.crypto/bcrypt
If you prefer to avoid specifying the proxy details each time you execute Go commands, consider defining an alias. This approach facilitates a seamless workflow, as exemplified below:
$ alias go='http_proxy=127.0.0.1:8080 go'
With this alias in place, Go commands can be executed normally, leveraging your designated HTTP proxy for all subsequent operations.
The above is the detailed content of How Do I Configure the Go Command to Work Behind a Proxy?. For more information, please follow other related articles on the PHP Chinese website!