Free through lesson 3

Go for Beginners

From setting up your environment through variables, control flow, slices and maps, functions and pointers, structs and interfaces, error handling, splitting packages, generics, concurrency and testing. Fifty lessons that take you to the point where you can assemble a tested tool using nothing but the standard library. Every piece of code and result shown was produced by actually running Go 1.27.1.

Curriculum

The 50 lessons are grouped into seven chapters. Working through them in order is the best way, but you are welcome to dip into whatever interests you. Note: this cannot run inside the browser, so try it with your own go run or the Go Playground (go.dev/play).

Chapter 1 — Fundamentals (lessons 1–9)

You get to grips with how Go runs and get to the point of executing it yourself with go run. You cover variables, zero values, numbers and strings and standard input, and how to read compiler errors.

Chapter 2 — Control flow (lessons 10–15)

You cover conditionals and repetition: if without parentheses, switch that does not fall through, for as the only loop, and breaking out with labels. You finish by assembling a number-guessing game.

Chapter 3 — Data structures (lessons 16–24)

You gather data with arrays, slices, maps and multiple dimensions. The crux of Go — that a slice shares its underlying array — is taken on head-on here, and you finish by aggregating sales data.

16

Arrays

The length is part of the type. Zero values are there the moment you declare it, and passing it to a function copies the whole thing. Which is why real code uses slices.

🔒 Basic
17

Slice basics

A slice is a triple of pointer, length and capacity. Slice it or pass it to a function and the underlying array is still shared.

🔒 Basic
18

append, and capacity (len and cap)

Always assign the result of append back. The difference between len and cap, and the trap where spare capacity lets you clobber the original.

🔒 Basic
19

Working with and sorting slices

The slices package from Go 1.21. Sort sorts in place. Filtering and transforming are written with for and append.

🔒 Basic
20

Map basics

A missing key gives you the zero value. The comma-ok idiom distinguishes a stored 0 from a missing key. The range order changes every time.

🔒 Basic
21

Maps in practice

Aggregation is one line: m[key]++. Output in key order, grouping, standing in for a set, and the fact that a map passed to a function is shared.

🔒 Basic
22

Getting the most out of range

What you get back depends on what you range over. The range value is a copy. The loop variable change in Go 1.22, and iterators.

🔒 Basic
23

Multidimensional slices

Building a table as a slice of slices. make happens in two stages, outer then inner. Writing aggregation by row and by column.

🔒 Basic
24

[Project] Aggregate sales data

Make one record a type, collect them in a slice, add into a map, repack and sort. All four stages of aggregation in one program.

🔒 Basic

Chapter 4 — Functions (lessons 25–32)

You give a piece of work a name and pull it out. Multiple return values and (result, error), variadic parameters, closures, defer, and on to pointers and recursion.

Chapter 5 — Types and interfaces (lessons 33–37)

You create your own data types. Structs and methods, embedding rather than inheritance, and interfaces with no implements keyword. You go as far as plugging your own types into the standard library's machinery.

Chapter 6 — Errors and data (lessons 38–43)

You learn systematically how failure is handled in a language with no exceptions. Wrapping with %w, panic and recover, files and JSON. You finish by designing an inventory system with structs.

Chapter 7 — Towards real work (lessons 44–50)

You cover splitting packages, generics, concurrency and testing. Finally you pull all 50 lessons together and see what to learn next.

Once you have finished all 50 lessons, look at Rust for Beginners, another compiled language that leans towards safety, or learn to ship in containers with Docker for Beginners. Membership unlocks every course.