Go Modules
Publish Go modules using Universal Release.
Detectionβ
Automatically detected when go.mod exists.
Configurationβ
ecosystems:
go:
enabled: true
validation:
build: true
test: true
lint: true
How Go Publishing Worksβ
Go modules are published via Git tags, not to a central registry:
- Tag your commit with semantic version
- Push tag to Git repository
- Go proxy (pkg.go.dev) discovers it automatically
Publishingβ
# Create and push Git tag
release publish --ecosystem go
This:
- Validates the module
- Creates a Git tag (e.g.,
v1.2.3) - Pushes tag to remote
- Notifies pkg.go.dev
Validationβ
Universal Release validates:
- β
go.modexists and is valid - β
Build succeeds (
go build) - β
Tests pass (
go test ./...) - β
Linting passes (
golangci-lint run) - β Module path is valid
Versioningβ
Go uses semantic versioning with v prefix:
# Create v1.2.3 tag
release version --bump minor
release publish --ecosystem go
Major Version Updatesβ
Go requires major version in import path:
// v1
module github.com/user/repo
// v2+
module github.com/user/repo/v2
Update go.mod for major versions:
# Update to v2
echo "module github.com/user/repo/v2" > go.mod
# Publish
release version --set 2.0.0
release publish --ecosystem go
Rollbackβ
Go doesn't support rollback. Bad versions remain but users can pin to good versions:
require github.com/user/repo v1.2.2 // pin to working version
Best Practicesβ
Module Structureβ
mymodule/
βββ go.mod
βββ go.sum
βββ pkg/
β βββ api/
β βββ api.go
βββ internal/
β βββ utils/
β βββ utils.go
βββ cmd/
βββ myapp/
βββ main.go
Configure go.modβ
module github.com/user/mymodule
go 1.21
require (
github.com/some/dependency v1.2.3
)
Use Semantic Import Versioningβ
// Import v1
import "github.com/user/repo/pkg/api"
// Import v2
import "github.com/user/repo/v2/pkg/api"
Validationβ
Enable comprehensive validation:
ecosystems:
go:
validation:
build: true
test: true
lint: true
vet: true
staticcheck: true
Proxy Integrationβ
After pushing tags, pkg.go.dev automatically discovers your module. You can trigger indexing:
# After publishing
curl "https://proxy.golang.org/github.com/user/repo/@v/v1.2.3.info"
Next Stepsβ
- Version Management - Semantic versioning
- Configuration - Advanced setup