Learn Go
Write, run and test small Go programs: slices, maps, errors, structs, interfaces, generics, goroutines, context and a tested command-line tool.
Go · Beginner · 10 lessons · 110 min
First steps
2 lessons
- 8 minBeginner
Install Go and run your first program
Install Go, create a module and run a first program with go run. You see what package main and func main do and how go run differs from go build.
- 10 minBeginner
Variables, types and constants in Go
Declare variables with var and :=, see zero values and types printed with %T, convert between numbers and use const. Fix a mismatched-types error.
Data and functions
3 lessons
- 11 minBeginner
Slices and maps in Go
Use slices as lists and maps as lookup tables: append, len, sub-slices, range, missing keys and the ok form. Fix a panic caused by a nil map.
- 11 minBeginner
Functions, multiple returns and errors in Go
Write functions with several results, return an error next to the value, check it with if err != nil, wrap it with %w and test it with errors.Is.
- 11 minBeginner
Structs and methods in Go
Group fields in a struct, add methods with value and pointer receivers, and see fmt use a String method. Fix a method that changes only a copy.
Interfaces and generics
2 lessons
- 10 minBeginner
Interfaces in Go: behaviour without classes
Describe behaviour with an interface, let types satisfy it by having the methods, and use any, type switches and fmt.Stringer. Fix a missing method.
- 10 minBeginner
Generics in Go: one function, many types
Write one function for many types with type parameters, constraints such as cmp.Ordered and your own union, and a generic Stack type. Fix a constraint error.
Concurrency and projects
3 lessons
- 12 minBeginner
Goroutines and channels: work at the same time
Start goroutines with go, wait with sync.WaitGroup, pass values over channels, build a small pipeline and use select. Fix a deadlock.
- 12 minBeginner
Context in Go: timeouts and cancellation
Pass a context.Context to running work, cancel it with WithCancel, set limits with WithTimeout and check ctx.Err(). Fix a function that ignores its context.
- 15 minBeginner
Packages, modules and go test
Know what a package and a module are, what makes a name exported, how to write table-driven tests with go test and how to build a small command-line tool.
Free AI coding tools to practise with
- AgentRouter Free Credits
Free AI coding credits: $25 per daily check-in and $50 per invite
No cardVerified
- Cline Free Models
Try select models free in Cline via rotating promotions with a usage quota
No cardVerified