Stage 1 · Code
Getting Started
The Go Toolchain
Meet the everyday Go commands that format, test, document, inspect, and manage projects.
One Command, Many Tools
Go ships with a complete command-line toolchain. Instead of installing separate formatters, test runners, documentation browsers, and package managers, you use subcommands of go.
go help
go help build
go help testgo help is built-in documentation. It is available even when you are offline.
| Command | Purpose | Typical use |
|---|---|---|
| go fmt ./... | Format Go source files | Before every commit |
| go vet ./... | Find suspicious code | Before sharing code |
| go test ./... | Run tests | During development |
| go doc fmt.Println | Read documentation | When learning an API |
| go env | Print Go environment settings | When debugging setup |
| go mod init | Start a module | At the beginning of a project |
| go get | Add or change dependencies | When using external packages |
Format, Check, Test
gofmt is Go's formatter. Most developers use go fmt, which runs formatting for packages. Formatting is intentionally standardized so teams do not spend time debating spacing.
go fmt ./...
go vet ./...
go test ./...The pattern ./... means the current package and all packages in subfolders.
go vet is not a full proof of correctness, but it catches common mistakes such as suspicious formatting calls. go test runs tests written in files ending with _test.go.
Go projects are easier to read because almost everyone uses the same formatter and the same basic commands. Learn these commands early and they will serve you everywhere.
Docs and Environment
The standard library is documented, and go doc lets you read that documentation from the terminal. You can ask about a package, type, function, or method.
go doc fmt
go doc fmt.Println
go env GOOS GOARCH GOPATH GOMODCACHEThese commands are useful when you are unsure what a function does or which platform Go is targeting.
Modules and Dependencies
A module is a versioned Go project. go mod init creates the go.mod file that records your module path and dependency requirements. You will use modules for almost every modern Go project.
go mod init example.com/weather
go get github.com/fatih/color@latest
go mod tidygo get adds or updates a dependency. go mod tidy cleans go.mod and go.sum so they match the imports in your code.
- Use
go fmtwhenever you save or before you submit code. - Use
go testafter behavior changes. - Use
go docwhen you meet a new package. - Use
go envwhen a setup or platform question appears. - Use
go helpwhen you forget a command's flags.
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.