Go quick reference
Go 1.27 essentials: variables and types, control flow, functions and errors, slices and maps, structs and interfaces, goroutines, input and files — and how a Go program is built and run in Zerethon IDE.
Written for Go 1.27. Examples that show an output were run in the Zerethon sandbox (Go 1.27) on 2026-10-24.
Basics
-
Hello, World
The smallest Go program:
package main,func main()andfmt.Println. -
Variables and types
varand:=, the basic types, constants, zero values and converting between types withstrconv. -
Conditions and loops
if/else,switch, andfor— Go's only loop — with a counter, a condition orrange. -
Functions and errors
Define functions with
func, return several values, and return anerrorinstead of throwing.
Data
-
Slices, arrays and maps
Grow a slice with
append, look up a map with the comma-ok form, and sort withslicesandsort. -
Structs, methods and interfaces
Group fields in a
struct, attach methods, and accept any type that has the right methods with an interface. -
Strings
The
stringspackage, formatting withfmt.Sprintf, bytes vs runes, and regular expressions withregexp. -
Goroutines and channels
Run functions concurrently with
go, wait withsync.WaitGroup, and pass results over a channel.
Input and files
-
Reading input (stdin)
Read what you type in the IDE's Input tab with
fmt.Fscanor line by line withbufio.Scanner. -
Reading and writing files
Read project files with
os.ReadFileoros.Open, parse CSV and JSON, and write temporary files under/tmp. -
Several files and packages
Split
package mainover several files in one folder; what the standard library offers without installing anything.
In Zerethon IDE
-
Running Go in Zerethon IDE
What Run builds, the time limit, input, tests, and what a run cannot do.
-
Common errors
Compile errors such as
declared and not usedandundefined, and runtime panics such asindex out of rangeandnil map. -
Official documentation
Where to read more: A Tour of Go, Effective Go, the standard library and the language specification.