Go Syntax References

Go syntax quick reference: slices, maps, structs, errors, goroutines and channels, from the Go specification. Every item below is clearly marked as a shortcut, command, or syntax reference.

Most Useful Go Syntax References

GoSyntax

Package and Main

Code example
package main func main() { }

The entry point of a Go program.

Learn More
GoSyntax

Print Output

Code example
fmt.Println("Hello") fmt.Printf("%d\n", n)

Prints a formatted line.

Learn More
GoSyntax

Declare a Variable

Code example
var n int = 1 name := "Ada"

Declares with var or the short := form.

Learn More
GoSyntax

Handle an Error

Code example
if err != nil { return err }

Checks a returned error.

Learn More
GoSyntax

Import Packages

Code example
import ( "fmt" "os" )

Imports standard packages.

Learn More
GoSyntax

If with Init Statement

Code example
if err := run(); err != nil { ... }

Runs a statement before the condition.

Learn More
GoSyntax

For Loop

Code example
for i := 0; i < 10; i++ { }

Go's only loop keyword.

Learn More
GoSyntax

Range Loop

Code example
for i, v := range items { }

Loops over a slice or map.

Learn More

More Go Syntax References

Frequently Asked Questions

What does this Go syntax reference cover?

It covers 21 common Go patterns and examples, including Package and Main, Print Output, Declare a Variable, Handle an Error, Import Packages.

Can I copy the Go examples?

Yes. Each reference page includes a copyable code example.

What affects these Go examples?

Check the linked documentation for language or runtime version requirements. Libraries, file paths, terminal quoting and environment settings can differ across systems; no blanket platform compatibility is implied.