go-dependency-management
Best practices for Go modules, dependency updates, and vulnerability scanning.
SKILL.mdskills/go/go-dependency-management/SKILL.md
GitHubCore Principles
- Commit
go.sum— It ensures reproducible builds and protects against supply-chain tampering. - Standard Library First — Always check if the standard library solves the problem before adding a dependency.
- Audit Regularly — Use
govulncheckto catch known vulnerabilities in your dependency tree. - Tidy Often — Run
go mod tidyto keepgo.modandgo.sumclean. - Semantic Versioning — Understand that Go modules follow SemVer (Major.Minor.Patch).
Common Commands
| Command | Purpose |
|---|---|
go mod init <name> |
Initialize a new module. |
go mod tidy |
Add missing dependencies and remove unused ones. |
go get <pkg>@latest |
Add or update a package to the latest version. |
go get -u ./... |
Update all dependencies to the latest minor/patch version. |
go mod vendor |
Create a local copy of dependencies in vendor/. |
go mod verify |
Verify dependencies against go.sum checksums. |
go mod why -m <pkg> |
Explain why a specific module is in your dependency tree. |
Vulnerability Scanning
Always run govulncheck before releasing code.
go install golang.org/x/vuln/cmd/govulncheck@latest
govulncheck ./...
Version Selection Strategy
go get -u=patch ./...: Safest way to update. Only applies bug fixes (patch versions).go get -u ./...: Updates to latest minor versions. May introduce new features or deprecations.replacedirective: Use ingo.modfor local development or patching broken upstream modules.
tools.go Pattern
To pin versions of CLI tools (like linters or code generators) used in the project:
//go:build tools
package tools
import (
_ "github.com/golangci/golangci-lint/cmd/golangci-lint"
_ "golang.org/x/vuln/cmd/govulncheck"
)
Anti-patterns
- ❌ Not committing
go.sum— Breaks build reproducibility. - ❌ Manual editing of
go.mod— Usego getorgo mod editinstead. - ❌ Ignoring
govulncheck— Shipping known vulnerabilities to production. - ❌ Adding unnecessary dependencies — Increases binary size and attack surface.
- ❌ Using
@masteror@mainversions — Use specific version tags or commit hashes for stability.