Creating a Go module
This guide describes how to create a Go module and prepare a ZIP archive for publishing to a Cloud Registry.
For more information on Go modules, see their official guides in the Go Modules Reference
Go module structure
Here is an example of a project structure:
mymodule/ # Go module root directory
│
├── go.mod # Defines the Go module and its dependencies
├── go.sum # Dependency checksums
├── main.go # Entry point (for executable Go modules)
│
├── pkg/ # Public packages
│ └── utils/
│ └── utils.go
│
└── internal/ # Private packages (not accessible outside the Go module)
└── config/
└── config.go
Creating your Go module
-
Install Go
. -
Create a directory for your Go module and open it:
mkdir mymodule && cd mymodule -
Initialize the Go module by specifying the full path under which it will be available in the registry:
go mod init registry.yandexcloud.net/go/<registry_ID>/mymoduleIn the project root, a
go.modfile will appear:module registry.yandexcloud.net/go/<registry_ID>/mymodule go 1.21 -
Add your Go module code; e.g., create a file named
hello.go:cat > hello.go << 'EOF' package mymodule func Hello() string { return "Hello from my module!" } EOF -
If you have external dependencies, synchronize
go.modandgo.sum:go mod tidy
Preparing a ZIP archive for publishing
The Go CLI does not support direct module publishing. To push to Cloud Registry, prepare a ZIP archive whose structure complies with Module zip files<full_module_path>@<version>/ format, where <full_module_path> matches the Go module name specified in go.mod.
Warning
Maximum ZIP archive size is 500 MB.
-
From the root of your Go module, build a ZIP archive, substituting your registry ID, module name, and version:
find . -type f | bsdtar -a -cf ../mymodule-v1.0.0.zip \ -s '|^\./|registry.yandexcloud.net/go/<registry_ID>/mymodule@v1.0.0/|' -T -Note
The
bsdtarutility is part of libarchive . It is preinstalled on macOS. On Debian and Ubuntu, install thelibarchive-toolspackage:sudo apt install libarchive-tools -
Verify the archive structure:
unzip -l ../mymodule-v1.0.0.zipResult:
Archive: ../mymodule-v1.0.0.zip Length Date Time Name --------- ---------- ----- ---- 74 2026-06-13 12:00 registry.yandexcloud.net/go/<registry_ID>/mymodule@v1.0.0/go.mod 112 2026-06-13 12:00 registry.yandexcloud.net/go/<registry_ID>/mymodule@v1.0.0/hello.go --------- ------- 186 2 files