Understand the contract

gofmt applies Go formatting conventions mechanically. Use go fmt ./... from a module root to format its packages, or gofmt -w main.go to rewrite one file. Formatting settles indentation and spacing so reviews can focus on behavior. It does not change a faulty algorithm into a correct one.

go vet examines source code for suspicious constructs, including some mismatches between formatting verbs and arguments. go test builds packages and executes their tests. These tools answer different questions, so a small validation loop should include all three rather than treating formatting as a complete code review.

Work through the example

Run the commands in the directory containing go.mod. The ./... pattern selects packages beneath the current directory, subject to Go package-pattern rules. Review the formatter diff before committing, then read any vet diagnostic alongside the source line that caused it.

go fmt ./...
go vet ./...
go test ./...
go build ./...

Watch this boundary

A clean vet result does not prove absence of races, input-validation problems or application bugs. Tests also depend on the cases you wrote. For example, a division function can pass a normal-input test while still failing on a zero divisor. Add behavioral expectations as you learn each feature.

Practice with a changed input

Deliberately misformat a copy of your greeting program and format it. Then change a Printf integer verb to %s and inspect the diagnostic from go vet.

References & further reading

Need help with your Go backend?

I work with engineering teams on focused Go and Kubernetes platform engagements, with limited consulting availability.

Explore Go consulting services