A Comprehensive Overview of Common Go Tools and Commands
This article surveys the essential Go command‑line utilities—including go help, get, build, install, fmt, env, test, and the extensive go tool suite such as pprof, trace, vet, and doc—while also highlighting popular third‑party tools like Delve, staticcheck, goconvey, go‑swagger, and others for debugging, testing, linting, and performance analysis.
This article provides a concise introduction to various Go (Golang) command‑line tools, their usage scenarios, and common flags. It covers official Go commands such as go help , go get , go build , go install , go fmt / gofmt , go env , go test , and the extensive go tool suite (e.g., go tool pprof , go tool trace , go tool compile , go tool vet , go tool doc , etc.). It also lists useful third‑party utilities for debugging, testing, code quality, and performance analysis, including Delve, goconvey, goleak, go‑wrk, go‑swagger, staticcheck, and many others.
Official Go Commands
go help <command> displays help for a specific subcommand. Example:
go help getgo get downloads or updates a module and its dependencies.
go get -u "github.com/VictoriaMetrics/fastcache"go build compiles packages and their dependencies. Use -x to see the compilation steps.
go build -x > result 2>&1go install builds and installs a package, similar to go build but also copies the binary to $GOPATH/bin .
go fmt / gofmt formats source files according to the official Go style.
gofmt -s -w *.gogo env prints Go environment variables; you can set them with go env -w .
go env -w GOPROXY="https://goproxy.com,direct"go test runs tests for a package. Coverage can be generated with -coverprofile and visualized via go tool cover .
go test -coverprofile=cover.out
go tool cover -html=cover.out -o coverage.htmlThe go tool Suite
Various low‑level utilities are available under go tool :
go tool pprof – performance profiling.
go tool trace – execution tracing.
go tool compile – compile a Go file to assembly ( -S ).
go tool vet / go vet – static analysis for common mistakes.
go tool doc – display documentation for Go identifiers.
go tool addr2line – translate program addresses to source locations.
go tool cover – generate HTML coverage reports.
go tool dist – manage Go distribution builds.
go tool fix – automatically update code to newer language versions.
go tool link – link object files into an executable.
go tool nm – list symbols in a binary.
go tool objdump – disassemble binaries.
go tool pack – create static libraries.
go tool test2json – convert test output to JSON.
Third‑Party Tools
delve – interactive debugger for Go programs.
goconvey – BDD‑style testing framework with web UI.
goleak – detect goroutine leaks.
go‑wrk – HTTP load testing tool.
go‑swagger – generate and validate Swagger/OpenAPI specs.
staticcheck – advanced static analysis (linting, bug detection).
goconst – find repeated string literals to replace with constants.
gocyclo – measure cyclomatic complexity of functions.
deadcode – detect unused code.
misspell – spell‑checking for source files.
revive – fast, configurable linter (alternative to golint).
gocode – code completion for editors like Vim.
godoctor – code refactoring assistance.
gops – inspect Go processes (memory, stack, etc.).
gotype – semantic analysis of Go code.
go‑mod family – module management (init, tidy, vendor, graph, verify, why, download, etc.).
References to official documentation and community tutorials are provided throughout the article.
Tencent Cloud Developer
Official Tencent Cloud community account that brings together developers, shares practical tech insights, and fosters an influential tech exchange community.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.