Loading Go Validator...

How to Check Go Code for Syntax Errors

Step 1

Add your Go code

Start with any Go file or snippet. It should be a whole file, starting with a package line, because that is what the Go spec calls a source file:

•
Paste it: copy the code straight from your editor
•
Upload a file: click Upload and pick a .go or .txt file from your Go module
•
Try the sample: click Sample to load a small program that passes the check

Example: a habit from another language

Coming from JavaScript, it is easy to type this:

package main

function greet() {
    fmt.Println("Hello")
}

The validator stops at line 3, column 1 with expected declaration, found function and explains that Go declares functions with func.

Step 2

Let it check

There is no button to press. Shortly after you stop typing, the code is read token by token with the same rules the Go parser uses, including the automatic semicolons Go adds at line ends. What that catches:

•
Structure: braces, brackets and parentheses that don't match, a missing package clause, statements outside a function
•
Literals: unclosed strings, raw strings, runes and comments, numbers like 0789 or 1__0
•
Layout rules: a missing trailing comma in a multi-line list, else or { on the wrong line
•
Not checked: types, undefined names, unused imports and variables, and go vet findings. Those need the compiler.
Step 3

Fix the first error

The result panel shows one of three things:

•
Syntax error: line and column, the parser's message, often a hint in plain words, and the line itself with a marker under the spot
•
Valid syntax: the file parses, with its package name and number of top-level declarations
•
Checking…: you just edited the code and the new version hasn't been checked yet

Once it parses, the Go Formatter can tidy the layout, and the Go Test Generator can write a table-driven test skeleton for its functions.

Frequently Asked Questions

What does the Go validator check?

It reads your code the way the Go toolchain's parser does (the same parser gofmt uses) and tells you whether the file is syntactically valid. That covers unbalanced braces and brackets, unclosed strings, raw strings, runes and /* comments, a missing package clause, statements like x := 1 outside a function, missing commas at the end of multi-line lists, else on its own line, malformed numbers such as 0789, and characters Go doesn't allow, such as smart quotes copied from a document.

What does it not check?

Anything past syntax. It doesn't type-check, so an undefined name, a wrong argument type or a missing return still look fine here. It also doesn't flag unused imports or variables, doesn't run go vet or a linter, and doesn't judge naming style. Run go build and go vet for those.

Why does it only show one error?

The Go parser reports the first problem it meets, and the errors after it are often knock-on effects of that one. The validator shows that first error with its line, column, the parser's own message and, for common mistakes, a plain-English explanation. Fix it and the check runs again by itself.

Does it understand generics, raw strings and build tags?

Yes. Type parameters and constraints like ~int | ~string, generic types such as List[T any], raw `backtick` strings with braces or // inside them, runes like '"' and '\'', labels and goto, select statements, struct tags, iota blocks and //go:build lines are all parsed as Go parses them. A file without a trailing newline is fine too.

The error points at a line after my mistake. Why?

Go adds semicolons at line ends for you, so some mistakes only become visible on the next token. A missing closing brace is reported where the file ends, and a missing comma is reported at the line break after the last element. For a never-closed brace the message also tells you which line opened it.

Is my code uploaded anywhere?

No. The check runs in your browser, nothing you paste or upload is sent to our server, and nothing is kept: reload the page and the editor is empty again.