go-tool
Compile, test, and analyze Go code
TLDR
List available tools
Run the go link tool
Print the command that would be executed, but do not execute it (similar to whereis)
View documentation for a specified tool
List all available cross-compilation targets
SYNOPSIS
go tool <command> [arguments...]
Example: go tool pprof [options] binary [profile]
PARAMETERS
cover
Generates and analyzes code coverage profiles for Go programs.
pprof
Analyzes and visualizations performance profiles (CPU, memory, mutex, block) generated by Go programs.
trace
Analyzes and visualizes Go execution traces, showing goroutine, network, syscall, and scheduler events.
vet
Examines Go source code for suspicious constructs, such as potential errors not caught by the compiler.
asm
The Go assembler. Translates Go assembly source files into object files. Usually invoked by 'go build'.
compile
The Go compiler. Compiles Go source files into object files. Usually invoked by 'go build'.
link
The Go linker. Links object files into an executable binary or a shared library. Usually invoked by 'go build'.
cgo
Cgo processes Go source files that import the pseudo-package 'C', enabling calls to C code.
DESCRIPTION
The go tool command serves as a gateway to various low-level utilities within the Go programming language's toolchain. Unlike standard Go commands like go build or go run, these tools are often invoked for advanced diagnostics, profiling, code analysis, or by the Go toolchain itself during the build process. It provides access to the Go compiler, assembler, linker, profiling tools (pprof), code coverage tools (cover), and static analysis tools (vet), among others. While some tools like go tool pprof are frequently used by developers, others like go tool compile are primarily internal components. Understanding go tool is essential for deep-diving into Go program behavior or for working on the Go compiler and runtime itself.
CAVEATS
The go tool command itself is not a standalone executable. It is a subcommand of the main go command and requires a Go language installation. The specific tools available via go tool can vary slightly between Go versions. Each sub-tool has its own set of arguments and usage patterns, which can be complex and are typically documented by running go tool <command> -h or consulting the Go documentation. Many of these tools are low-level and are primarily used by advanced Go developers or for debugging Go's internal mechanisms.
COMMON USAGE SCENARIOS
While many go tool subcommands are used internally by the Go toolchain, go tool pprof and go tool trace are frequently used by developers to diagnose performance bottlenecks and understand runtime behavior. go tool cover is crucial for assessing test coverage. go tool vet helps in identifying potential issues in code before compilation.
DISCOVERING AVAILABLE TOOLS
To list all tools available through go tool on your system, you can typically run go tool without any arguments. This will print a list of recognized commands. For help on a specific tool, use go tool <command> -h or go tool <command> help.
HISTORY
The go tool command and its various sub-tools have been an integral part of the Go programming language's distribution since its early versions. As the Go project matured, the specific set of available tools and their functionalities evolved to support new features, debugging capabilities, and performance analysis requirements of the language and runtime. It serves as a consistent interface to the underlying components of the Go toolchain, ensuring that even as internal implementations change, developers can still access these utilities through a stable command.