Go Formatter
Format Go source with gofmt, including gofmt -s simplifications. Syntax errors come back with a line and column.
Go is the one language whose layout is defined by its toolchain rather than by taste, which is why every Go file looks the same. gofmt is that definition, and re-implementing it in JavaScript would produce a second answer that agrees almost always — the failure mode that only appears in the one file a reviewer is reading. The -s option is offered because it is part of the same tool: it rewrites a slice of explicitly typed composites (the []T with a T{…} element) as the shorter form, and drops redundant type declarations.
Paste Go source and press the button; this page sends it to `gofmt` on the tool server and shows the formatted source back, with a copy button.
The `gofmt -s` checkbox asks for the simplification pass as well, which rewrites some composite literals and slices into their shorter forms.
It is the one page in this family that is not a browser-only converter: the source is posted to the tool server for the run, and the result is gofmt's own output rather than a re-implementation.
What happens between the button and the result
The page posts the source and the simplify flag to the tool-execution endpoint and renders the `result` field. The `info` field, when present, is shown under the output.
A parse error comes back as a refusal carrying gofmt's own message, so the line and column it names are gofmt's. An empty editor is answered before any request is made.
Nothing runs on page load. The output panel stays a placeholder until the button is pressed, which is why opening the page costs no run.
- Formats with gofmt, not with a JavaScript parser
- `gofmt -s` adds the simplification pass
- A refusal keeps gofmt's message and the run reference
What formatting does not fix
gofmt normalises layout — indentation, alignment, spacing and line breaks — and leaves the program's meaning alone. A missing import or an unused variable is a compiler error, not a formatting one.
The simplify pass can change how an expression is written, so a diff of its output is larger than a plain formatting diff. Turn it off when you want the smallest possible change.
How to use the source box
Paste the Go source into the Go Source box, tick the `gofmt -s` checkbox when the simplification pass is wanted, and press Format with gofmt. The source is posted to the tool server for the run.
Read the Formatted panel and copy it out. The output is `gofmt`'s own, the one page in this family that is not a browser-only converter, and nothing runs on page load.
What to Expect
Best for
- Formatting a snippet before pasting it into a review
- Checking what gofmt does to a piece of code
- Applying the simplification pass without a local Go install
Not ideal for
- Compiling or type-checking the code, which formatting does not do
- A whole module or several files at once
- Code that does not parse, which comes back as an error with no output
What this tool keeps
- Comments, in place, as gofmt places them
- String literals exactly as written
- The program's behaviour, since only layout and the optional simplifications change
What may need cleanup
- A larger diff than expected when the simplify flag is on
- An import block that gofmt groups but does not add to
- Code that parses but does not compile, which formats cleanly and still fails to build
Common errors
- Reading a parse error as a formatter failure
- Expecting gofmt to add a missing import
- Leaving the simplify flag on and reviewing a noisy diff
Example use cases
- Formatting a snippet from a bug report before replying
- Showing a team what `gofmt -s` changes
- Cleaning up code pasted out of a document
Sample input
A one-line main function with three statements crammed onto one line and a map literal.
Sample output
The same function laid out across several lines with gofmt's indentation, and a shorter map literal when simplify is ticked.
Who this is for
- Go developers without a local toolchain to hand
- Reviewers formatting a pasted snippet
- Anyone learning what gofmt and `-s` actually change
Frequently asked questions
Where does the Go formatting happen?
The source is sent to gofmt on the tool server and returned formatted, with a copy button.
Does formatting compile or type-check my program?
No. A program that parses but does not compile still formats cleanly and fails to build.
Why did the diff look larger than expected?
The simplify flag applies gofmt's optional simplifications, which change more than whitespace.
Build custom tools for your store
Join the SDK program to create useful ecommerce utilities for your store.