Skip to main content
During our module discussion, we discussed some go commands related to go modules. Let’s now discuss some other important commands that are essential for Go development.

Formatting with go fmt

go fmt formats the source code and it’s enforced by the language so that we can focus on how our code should work rather than how our code should look.
go fmt
This might seem a little weird at first especially if you’re coming from a JavaScript or Python background, but frankly, it’s quite nice not to worry about linting rules.

Validating with go vet

go vet reports likely mistakes in our packages. If you make a mistake in the syntax and then run go vet, it will notify you of the errors.
go vet

Environment Information with go env

go env prints all the Go environment information. We’ll learn about some of these build-time variables later.
go env

Documentation with go doc

go doc shows documentation for a package or symbol. Here’s an example of viewing the fmt package:
go doc -src fmt Printf

Other Useful Commands

You can use the go help command to see what other commands are available:
go help
Here are some additional important commands:

go fix

Finds Go programs that use old APIs and rewrites them to use newer ones.

go generate

Usually used for code generation.

go install

Compiles and installs packages and dependencies.

go clean

Used for cleaning files that are generated by compilers.
Some other very important commands are go build and go test, which we will learn about in detail later in the course.

Build docs developers (and LLMs) love