Around Go: command line · 3 MIN READ
Go toolbelt: modules, tests, vet and build
Use the native Go CLI to inspect a module and check a service before packaging it.
A useful Go development loop checks the module boundary, formatting, tests, static diagnostics and the final build. These commands are for the native Go toolchain on a development machine; platform support and build tags can change which packages are selected.
Locate the module and inspect dependencies
go version identifies the toolchain. go env GOMOD GOWORK prints selected module/workspace files without dumping every environment setting. list -m all describes the selected build list; mod why explains why a dependency is needed.
go version
go env GOMOD GOWORK
go list -m all
go mod why -m golang.org/x/syncRun inside your module; the selected module file should be the one you expect. The last dependency is an example: if it is not required, Go explains that. Module commands may access the configured proxy and network.
Format, test and inspect suspicious code
gofmt -l lists formatting differences without rewriting files. test checks packages; -race adds supported native race instrumentation. vet reports suspicious constructs rather than proving semantic correctness. A clean run still depends on meaningful tests.
gofmt -l .
go test ./...
go test -race ./...
go vet ./...Run each check and inspect its status. Race detection needs a supported native platform/toolchain and may require cgo; it is not available through every cross-compilation target. A race-free test run covers only paths actually exercised.
Tidy deliberately and inspect the shipped binary
mod tidy can add or remove module requirements and sums, so review its diff rather than running it as an invisible deployment step. build -trimpath removes local filesystem paths from the executable; version -m inspects embedded build/module metadata.
go mod tidy
git diff -- go.mod go.sum
mkdir -p bin
go build -trimpath -o ./bin/api ./cmd/api
go version -m ./bin/apiThe example assumes cmd/api exists. Test any module file changes before committing. Embedded build metadata is useful for provenance, but build flags and source state must still be recorded for reproducible releases.
TAKE THIS WITH YOU
Check the selected module, format, test, race-check where supported, run vet and inspect the final artifact. Review dependency-file changes explicitly instead of treating tidy as a harmless read-only command.
Check your understanding
What should you do after go mod tidy?
Go to the source
Progress stays in this browser. No account needed.