gofmt
The standard Go formatter, which rewrites source code into the one agreed layout so nobody argues about style.
In more detail
gofmt has no configuration: tabs for indentation and one brace style for everyone. The -l flag lists files that are not formatted, which makes a good pipeline check, and -w rewrites them in place. Most editors run it every time you save; go fmt is a shortcut that runs it over packages.
Examples
gofmt -l .gofmt -w main.goRelated terms
- go command — The single command-line program that ships with Go and builds, runs, tests, formats and documents your code through subcommands.
- go vet — The go subcommand that looks for code that compiles but is probably wrong, such as a print format verb that does not match its argument.
Taught in
- Installing the Go Toolchain — Concurrent Systems Programming with Go