Skip to content

Latest commit

 

History

History
40 lines (26 loc) · 2.63 KB

GOPROXY.md

File metadata and controls

40 lines (26 loc) · 2.63 KB

GOPROXY

The GOPROXY environment variable in Go specifies the proxy server that Go uses to retrieve module dependencies. Understanding how to configure GOPROXY is essential for efficient and reliable dependency management when working with Go modules.

Purpose of GOPROXY

GOPROXY serves the following purposes:

  • Proxy Control: GOPROXY allows control over the source from which Go modules are downloaded. By specifying a proxy server, you can enhance the security, reliability, and performance of module downloads.

Configuring GOPROXY

  1. Setting Values:

    • Direct URL: Set GOPROXY to a specific module proxy server's URL, e.g., GOPROXY=https://proxy.example.com.
    • Multiple Proxies: Specify multiple proxy servers separated by commas. Go will attempt to download modules from each in order until it succeeds, e.g., GOPROXY=https://proxy1.example.com,https://proxy2.example.com.
  2. Public Proxies:

    • Several public module proxy servers are available, making it easy to get started with Go modules. The official Go proxy, https://proxy.golang.org, is commonly used by default. Other public proxies include JFrog’s JCenter, Google’s Cloud Source Repositories, and more.
  3. Private Proxies:

    • Organizations can set up private module proxy servers to control access to internal dependencies and ensure faster, more reliable builds. Private proxies can be specified using GOPROXY.
  4. Fallback Behavior:

    • If a module cannot be found on the specified proxy server(s), Go will fall back to checking the public proxy (https://proxy.golang.org) and the original module source (e.g., a Git repository or version control system).
  5. Security:

    • Using a trusted proxy server (public or private) adds a layer of security to dependency management. Proxy servers can validate modules and ensure they have not been tampered with, protecting projects from potential security risks.
  6. Offline Mode:

    • By setting GOPROXY=off, you can disable the use of any proxy server, forcing Go to use only the local filesystem for module resolution. This is useful for working offline or in restricted network environments.

Example Usage

To use a specific proxy server (https://proxy.example.com) with go install, set GOPROXY before executing the command:

GOPROXY=https://proxy.example.com 
go install ./...

By understanding and effectively utilizing GOPROXY, you can optimize module dependency management in Go, ensuring faster, more secure, and reliable builds for your projects. Adjust GOPROXY based on your project's requirements and network environment to achieve efficient module resolution.