FormatCodes
Home/Go Tools/Go Formatter

Go Formatter

Format and validate Go code online for free with the official gofmt, right in your browser.

Local browser processing
No sign-up required
Powered by official gofmt
Language
Gomain.go
gofmt style is fixed: tab indentation · no configurable optionsQuick format
InputEditable
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
OutputGo valid45 lines · 699 B
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"fmt"
"strings"
"sort"
)
type User struct {
ID int
Name string
Email string
Active bool
}
func (u User) String() string {
return fmt.Sprintf("%s <%s>", u.Name, u.Email)
}
func filterActive(users []User) []User {
result := make([]User, 0)
for _, u := range users {
if u.Active {
result = append(result, u)
}
}
return result
}
func main() {
users := []User{
{1, "Alice", "[email protected]", true},
{2, "Bob", "[email protected]", false},
{3, "Carol", "[email protected]", true},
}
active := filterActive(users)
sort.Slice(active, func(i, j int) bool {
return strings.ToLower(active[i].Name) < strings.ToLower(active[j].Name)
})
for _, u := range active {
fmt.Println(u)
}
}
UTF-8 · Tab indent · gofmtLocal processing · Ready
How It WorksGo
Overview
This Go formatter cleans up code with inconsistent indentation or mixed styles into a standard format, powered by a WebAssembly build of gofmt. The output is identical to running go fmt locally. Everything runs locally in your browser; your code never leaves your device.
Use Cases
Format code pasted from docs or generated by AIClean up legacy code with inconsistent indentationValidate whether syntax is correctUnify a team's Go code style
Steps
123
Paste or uploadAuto-formatGet the result

Related Tools

Related Guides

Frequently Asked Questions

Search Tools

Search 55+ formatting, conversion, minification, diffing, and generation tools