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.go

Related terms

Taught in

References