Pulling a Go module from a Cloud Registry
To pull a Go module, you need the cloud-registry.artifacts.puller role or higher.
You can pull Go modules using the standard go command: your Cloud Registry operates as a Go proxy and implements Module Proxy Protocol
Environment setup
-
Specify the registry as a proxy for Go modules and disable checksum verification via the public Go checksum database
for Go modules within your registry:export GOPROXY=https://registry.yandexcloud.net/go/<registry_ID>,https://proxy.golang.org,direct export GONOSUMDB=registry.yandexcloud.net/*Where:
GOPROXY: Comma-separated list of Go proxies. Thegocommand searches for a Go module in every source, one by one:https://registry.yandexcloud.net/go/<registry_ID>: Your Cloud Registry.https://proxy.golang.org: Public Go proxy for modules from public repositories.direct: Direct access to a VCS repository, e.g., GitHub, if the Go module was not found in any of the proxies.
GONOSUMDB: Path templates of Go modules to skip checksum verification for.
-
Provide the registry authentication credentials. The
gocommand only supports basic authentication, so we recommend providing the credentials via the~/.netrcfile.IAM tokenAPI keyAdd the following line to the
~/.netrcfile:machine registry.yandexcloud.net login iam password <IAM_token>For authentication with an API key, specify
yc.cloud-registry.artifacts.pullas the key scope.Add the following line to the
~/.netrcfile:machine registry.yandexcloud.net login api_key password <API_key>Note
Read access to the
~/.netrcfile must be restricted to its owner. Set the access permissions:chmod 600 ~/.netrc
Adding a Go module to a project
-
Navigate to the Go project root where the
go.modfile resides. -
Add the required version of the Go module:
go get registry.yandexcloud.net/go/<registry_ID>/<module_name>@<version>For example:
go get registry.yandexcloud.net/go/e5o6a2blpkb6********/mymodule@v1.0.0This command will pull the Go module to the local cache and add a corresponding record to
go.modandgo.sum:go: added registry.yandexcloud.net/go/e5o6a2blpkb6********/mymodule v1.0.0 -
Optionally, if the Go module is already used in your code via the
importdirective, synchronizego.modandgo.sum:go mod tidy -
Optionally, pull all project dependencies to the local cache without executing a build:
go mod download
Useful links
Scope is an API key parameter that restricts the key's use to specific operations in addition to the service account's access permissions. For details, see API keys with scope and validity limits.