Ecosystem of Tools
The tools bundled with the Go language are built according to the Unix philosophy: one tool for one task. This is no
surprise, as one of Go’s creators is Ken Thompson 1, a father of the Unix operating system. That heritage clearly
influenced the language’s focus on simplicity and pragmatism. Starting with Go 1.21, the distribution focuses on a
seamless toolchain experience, where the go command automatically manages and switches between version-specific
toolchains 2 as needed.
The go command is the entry point for a wide array of subcommands. You can view the full list by running:
$ go help
(...)
The commands are:
bug start a bug report
build compile packages and dependencies
clean remove object files and cached files
doc show documentation for package or symbol
env print Go environment information
fix apply fixes suggested by static checkers
fmt gofmt (reformat) package sources
generate generate Go files by processing source
get add dependencies to current module and install them
install compile and install packages and dependencies
list list packages or modules
mod module maintenance
work workspace maintenance
run compile and run Go program
telemetry manage telemetry data and settings
test test packages
tool run specified go tool
version print Go version
vet report likely mistakes in packages
(...)
You can view the description for any specific command by running go help [command]. Each of these tools has its place in
the development lifecycle, and as a Go developer, you will use them daily.
While the Go language itself is a study in minimalism, its true power is unlocked through this ecosystem. You can
leverage cross-compilation 3 to build a binary for a completely different platform with a single flag. You can manage
dependencies effortlessly using the go.mod file and the go get command. You can install binaries directly to your GOPATH
with go install, and manage Go-specific environment variables via go env.
The go test command is a powerhouse in its own right—use it to run unit tests, test coverage, clear caches, detect
race conditions 4, and execute precise performance benchmarks 5. You can even inspect existing binaries to
see exactly which compiler version and dependencies produced them using go version 6.
Go has static code analysis tool go vet command 7 which catches things the compiler doesn’t and doesn’t require you to
write a test. It bundles a lot of different analyzers (append, test, waitgroup), each analyzing a specific potential
issue with the code.
Next we have go fix command 8 which bundles advanced suite of algorithms to identify opportunities for code
improvement, helping you automatically adopt modern language features and standard library optimizations in legacy projects.
You run the go fix ./... command and it will automatically update relevant peaces of code to most modern equivalents.
Go language also gives tools for analyzing runtime performance of our binary (pprof and trace) for analyzing CPU
profile and memory profile 9.
Another powerful (yet rarely used and often misunderstood) feature of Go is multi-module workspaces provided by the
go work command 10. With multi-module workspaces, you can tell the Go command that you’re writing code in multiple
modules at the same time and easily build and run code in those modules.
These tools are the key pillars of the Go philosophy: powerful minimalism and are crucial for idiomatic, bug-free, testable, performant code. They ensure the developer focuses on solving real problems, leaving dealing with “boring” stuff for the tools.
“Gofmt’s style is no one’s favorite, yet gofmt is everyone’s favorite.”, Go Proverb
- https://pl.wikipedia.org/wiki/Ken_Thompson
- https://www.zenofgo.blog/blog/manage-go-versions-without-package-manager.html
- https://www.zenofgo.blog/blog/cross-platform-compilation.html
- https://go.dev/blog/race-detector
- https://pkg.go.dev/testing#hdr-Benchmarks
- https://www.zenofgo.blog/blog/inspecting-go-binaries-with-go-version-tool.html
- https://pkg.go.dev/cmd/vet
- https://go.dev/blog/gofix
- https://go.dev/blog/pprof
- https://go.dev/doc/tutorial/workspaces