| name | go-modules |
| description | Go modules and dependency management |
| sasmp_version | 1.3.0 |
| bonded_agent | 01-go-fundamentals |
| bond_type | SECONDARY_BOND |
Go Modules Skill
Master Go module system and dependency management.
Overview
Complete guide for Go modules including versioning, private modules, vendoring, and dependency updates.
Parameters
| Parameter | Type | Required | Default | Description |
|---|
| action | string | yes | - | Action: "init", "tidy", "vendor", "update" |
| private | bool | no | false | Handle private modules |
Core Topics
Module Initialization
go mod init github.com/myorg/myapp
go mod download
go mod tidy
go mod verify
go.mod Structure
module github.com/myorg/myapp
go 1.22
require (
github.com/gin-gonic/gin v1.9.1
github.com/jmoiron/sqlx v1.3.5
go.uber.org/zap v1.26.0
)
require (
github.com/lib/pq v1.10.9
)
Private Modules
go env -w GOPRIVATE=github.com/myorg/*
git config --global url."git@github.com:".insteadOf "https://github.com/"
git config --global url."https://${GITHUB_TOKEN}@github.com/".insteadOf "https://github.com/"
Vendoring
go mod vendor
go build -mod=vendor ./...
go mod verify
Dependency Updates
go list -m -u all
go get github.com/gin-gonic/gin@latest
go get -u ./...
go get github.com/gin-gonic/gin@v1.9.1
go get github.com/gin-gonic/gin@v1.8.0
Replace Directives
replace github.com/myorg/shared => ../shared
replace github.com/original/pkg => github.com/myorg/pkg-fork v1.2.3
exclude github.com/vulnerable/pkg v1.0.0
Workspace (Go 1.18+)
go 1.22
use (
./api
./shared
./worker
)
go work init ./api ./shared
go work use ./worker
go work sync
Troubleshooting
Failure Modes
| Symptom | Cause | Fix |
|---|
| Module not found | Private repo | Set GOPRIVATE |
| Checksum mismatch | Proxy cache | GOPROXY=direct |
| Version conflict | Diamond dependency | Use go mod graph |
Debug Commands
go mod graph
go mod why github.com/pkg/errors
go list -m -versions github.com/gin-gonic/gin
Usage
Skill("go-modules")