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.

about 3 hours in total (estimate)

Slides for this course (for classes and in-house training) →

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.

1

What Go is (setting up and Hello World)

Go's three defining traits, and installing it. Running the four lines that start at package main and func main() with go run.

about 3 min Free preview Free
2

Output with fmt, and comments

When to use Println, Print, Printf and Sprintf. Reading format verbs, and what %!d(string=…) means.

about 4 min Free
3

Variables, types and type inference

When to use var and when :=. There are zero values, so an uninitialized variable does not exist. Types never convert automatically.

about 3 min Free
4

const and iota

Values you never change are const. Producing a sequence with iota and adding your own type and a String() method to make a Go enum.

about 3 min 🔒 Basic
5

Numeric types and operators

Dividing two integers truncates. int and float64 cannot be mixed. Overflow wraps around silently.

about 3 min 🔒 Basic
6

String basics (string, byte and rune)

A string is UTF-8 bytes. len() returns the byte count. The difference between byte and rune, and how to slice non-ASCII text.

about 3 min 🔒 Basic
7

Working with strings using the strings package

Search, transform, split, trim and join. Organizing the strings functions by purpose, and speeding up concatenation with Builder.

about 4 min 🔒 Basic
8

Standard input and strconv

Reading a line with bufio.Scanner and converting with strconv. Conversion functions return a value and an error — this is Go's rhythm.

about 3 min 🔒 Basic
9

Reading compiler errors, and go vet

Read an error starting from file:line:column. The seven most common messages and their fixes, and what go vet is for.

about 3 min 🔒 Basic

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.

about 3 min 🔒 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.

about 3 min 🔒 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.

about 3 min 🔒 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.

about 3 min 🔒 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.

about 3 min 🔒 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.

about 3 min 🔒 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.

about 4 min 🔒 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.

about 3 min 🔒 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.

about 3 min 🔒 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 — Toward 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 toward safety, or learn to ship in containers with Docker for Beginners. Membership unlocks every course.