liveBook · Manning

Gofmt

gofmt is Go’s standard source-code formatter, applying the language’s canonical formatting style automatically.

How 3 Manning books explain it

Go in Practice, Second Edition

go fmt is a Go command that reformats Go source files according to the language's canonical formatting style.

How it is used
Keeps shared Go source consistently formatted as part of everyday development.
How deep it goes
Shows a before-and-after diff and a preview command, while leaving some newline and import-declaration choices to developers.
Examples
Uses a poorly formatted Go file and a `gofmt -d` diff showing whitespace, indentation, and semicolon changes.
What you can do after
Operate/configure it by running `go fmt`, previewing changes with `gofmt -d`, or enabling IDE formatting.

Read how Go in Practice, Second Edition explains gofmt →

Go in Action, Second Edition

gofmt is the standard Go source-code formatter that applies the official Go formatting style.

How it is used
Standardizes Go source layout so developers can focus reviews and collaboration on behavior rather than formatting preferences.
How deep it goes
Explains parsing, rewriting, formatting modes, and editor use, but does not descend into formatter implementation internals.
Examples
Demonstrates `gofmt -d main.go`, its sample diff, and `gofmt -w main.go` for in-place rewriting.
What you can do after
Operate/configure it via `gofmt -d` for inspection and `gofmt -w` for direct file rewriting.

Read how Go in Action, Second Edition explains gofmt →

Shipping Go: Develop, deliver, discuss, design, and go again

The standard Go source-code formatter that applies the language's canonical formatting conventions.

How it is used
Standardizes Go source formatting and turns style consistency into an automated merge check.
How deep it goes
Explains visible formatting changes and CI enforcement, but does not detail formatter internals.
Examples
Uses go fmt ./..., a Makefile check-format target, and a pull-request format-check job.
What you can do after
Operate/configure gofmt locally and enforce clean formatting through a CI merge gate.

Read how Shipping Go: Develop, deliver, discuss, design, and go again explains gofmt →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.