The go toolchain

Contents
go build
go vet finds bugs
gofmt your code
Read docs locally

go build

The go tool builds, tests, formats, and documents your code, so a fresh machine needs little beyond the toolchain itself. Start with build: from the module root, one command compiles every package and drops a runnable binary next to your code.

package main import "fmt" func main() { fmt.Println("hello, Go") }

go build -o hello

./hello

hello, Go

The first command compiles the program into a file named hello, and the second runs it. While experimenting, go run main.go compiles to a temporary file and runs it in one step.

go vet finds bugs

The compiler accepts many suspicious programs that still run, such as a Printf call with fewer arguments than verbs. The vet command scans for these classic mistakes and reports them before they reach production.

package main import "fmt" func main() { name := "Go" fmt.Printf("%s %s\n", name) }

go vet

# example.com/hello
./main.go:7:5: fmt.Printf format %s reads arg #2, but call has 1 arg

The format asks for two strings, but the call passes one, so vet points at the exact line and column. Run vet over your module before every review: it costs a second and catches what eyes skip.

gofmt your code

The gofmt tool rewrites spacing and alignment into the one true style, ending debates about indentation and brace placement. The -l flag lists files that differ from the standard, and -w rewrites them in place, so run it before every commit.

gofmt -l .

main.go

The output names main.go as a file that needs formatting. After gofmt -w main.go, the same listing prints nothing, which means the whole module matches the standard style.

Read docs locally

Your installed toolchain carries its own manual. The go doc command prints documentation for any package or symbol without opening a browser, which helps when the network is gone or a signature slips your mind.

go doc fmt.Println

package fmt // import "fmt"
func Println(a ...any) (n int, err error)
Println formats using the default formats for its operands and writes to standard output.

One command shows the signature plus a one-paragraph summary. Explore from there: go doc fmt opens the whole package, and go doc time.Duration narrows down to a single type.

Next: Testing with go test

Article author: Arthur Isaev

Related articles
Golang
Go course: zero to hero in 50 lessons
What is Go and where it runs
Install Go and check the version
Your first Go program
Modules with go mod
Variables
Constants
Types
Numbers
Strings
Conditions with if
Switch in Go
Loops with for
Arrays in Go
Slices in Go
Maps in Go
Functions in Go
Errors as values
Pointers in Go
Structs in Go
Methods in Go
Interfaces in Go
Embedding instead of inheritance
Generics in Go
Packages and imports
The go toolchain
Testing with go test
Advanced errors
defer in Go
Strings, bytes and runes
Time in Go
JSON
Files and IO
HTTP servers
HTTP clients
Context
Goroutines
Channels
select and sync
CLI: args, flags, env
Logging
Regular expressions
Sorting
Concurrency patterns
Databases with database/sql
Benchmarks and profiling
Toolchain and CI
Project layout
Capstone: wordfreq CLI
Capstone: JSON API server
Hero roadmap: the whole course on one page
Install Go on Windows 11
Install Go on Ubuntu
Install Go on Rocky Linux
Install Go on macOS
Install Go on FreeBSD
Go in Docker

Search this site

Channel @aofeed Chat @aofeedchat

Contacts and cooperation:
I recommend our hosting beget.ru
Write to info@urn.su, info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: