Go Quick Reference
Go essentials: variables, slices, maps, structs, interfaces, errors, goroutines, channels and the go tool.
6 sections · 39 snippets · updated Oct 14, 2026
Click any snippet to copy it.
Basics
Programs and variables.
TaskCode
- Hello world
- Variables
- Multiple assignment
- Print formatted
- Convert
Slices & maps
Collections.
TaskCode
- Slice
- Make with length
- Slice of a slice
- Loop
- Sort
- Contains
- Reverse
- Map
- Check a key
- Delete a key
Control flow
Conditions and loops.
TaskCode
- If with init
- For (the only loop)
- Range over an integer (1.22+)
- Switch
- Defer
Functions, structs & interfaces
Types and methods.
TaskCode
- Function with multiple returns
- Struct
- Method
- Pointer receiver
- Interface
- Generics
- Struct tags (JSON)
Errors & concurrency
Error handling, goroutines and channels.
TaskCode
- Check an error
- Wrap an error
- Check error type
- Goroutine
- Channel
- Wait group
- Select
Go tool
Build, test and modules.
TaskCode
- Start a module
- Run / build
- Test
- Add / tidy dependencies
- Format / vet