2025-03-14 21:59:59 -06:00
|
|
|
# gofmt
|
|
|
|
|
|
|
|
|
|
> Format Go source code.
|
2025-07-24 22:27:13 -06:00
|
|
|
> More information: <https://pkg.go.dev/cmd/gofmt>.
|
2025-03-14 21:59:59 -06:00
|
|
|
|
|
|
|
|
- Format a file and display the result to the console:
|
|
|
|
|
|
|
|
|
|
`gofmt {{source.go}}`
|
|
|
|
|
|
|
|
|
|
- Format a file, overwriting the original file in-place:
|
|
|
|
|
|
|
|
|
|
`gofmt -w {{source.go}}`
|
|
|
|
|
|
|
|
|
|
- Format a file, and then simplify the code, overwriting the original file:
|
|
|
|
|
|
|
|
|
|
`gofmt -s -w {{source.go}}`
|
|
|
|
|
|
|
|
|
|
- Print all (including spurious) errors:
|
|
|
|
|
|
|
|
|
|
`gofmt -e {{source.go}}`
|