Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Leer Working with Private Modules | Section
Practice
Projects
Quizzes & Challenges
Quizzen
Challenges
/
Go Modules and Package Management

bookWorking with Private Modules

Veeg om het menu te tonen

When working with Go modules, you often use public repositories as dependencies. However, in many organizations, you will need to depend on code that is stored in private repositories. This introduces several challenges, such as configuring authentication so Go tools can fetch the code, and ensuring that your build process respects the privacy of your organization’s code. Go provides mechanisms to manage these challenges, but you must understand how to configure your environment and tooling to work smoothly with private modules.

go.mod

go.mod

copy
12345678910
module example.com/myapp go 1.21 require github.com/myorg/private-lib v1.2.3 // Private module hosted on a private repository // To use this private module, set the GOPRIVATE environment variable: // export GOPRIVATE=github.com/myorg/* // And make sure your git credentials (SSH keys or HTTPS tokens) are configured. // Without this, 'go get' and 'go mod tidy' will fail to fetch the private module.

Go uses several environment variables to control how modules are fetched and how private modules are handled. The most important is GOPRIVATE, which tells the Go toolchain which module paths should be considered private. When a path matches GOPRIVATE, Go skips the public proxy and checksum database, and fetches code directly from your version control system. This prevents sensitive code from being shared or checked by public infrastructure.

Another related environment variable is GONOPROXY. This variable specifies which module paths should bypass the Go proxy, even if the proxy is enabled for other modules. This is useful if your organization runs its own proxy or you want to avoid using the public proxy for certain modules.

By configuring GOPRIVATE and GONOPROXY appropriately, you can ensure that private code is fetched securely and never leaves your organization’s control. You will also need to make sure your authentication (such as SSH keys or HTTPS tokens) is set up, so the Go toolchain can access your private repositories when needed.

question mark

What is the main purpose of the GOPRIVATE environment variable in Go module management?

Select the correct answer

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 1. Hoofdstuk 13

Vraag AI

expand

Vraag AI

ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

Sectie 1. Hoofdstuk 13
some-alt