thecodex.expert · The Codex Family of Knowledge
Track 1 — Foundations

Go: Foundations

Five lessons covering Go's core syntax, data structures, and first steps into goroutines.

🕐 ~4 hours5 lessonsGo 1.23

Lessons

Lesson 1

Variables, types, and control flow

var, :=, basic types (int, float64, string, bool), if/else, for (Go's only loop), switch, and zero values.

What to look for:

  • := is short variable declaration — var x int = 5 and x := 5 are equivalent inside functions
  • Zero values: int is 0, string is "", bool is false — no uninitialised variables
  • Go has ONE loop keyword: for. It does while, do-while, and C-style for
  • switch cases do not fall through by default — no break needed
🕑 45 min
Lesson 2

Functions, multiple returns, and defer

Function syntax, multiple return values, named returns, defer, panic, and recover.

Prerequisite: Lesson 1

What to look for:

  • Multiple return values: func divide(a, b float64) (float64, error)
  • defer runs when the function returns — use for cleanup (close files, unlock mutexes)
  • Multiple defers run LIFO (last in, first out)
  • panic is not for normal errors — use error returns instead
🕑 45 min
Lesson 3

Structs, methods, and pointers

Struct definition, field access, value vs pointer receivers, new(), and & / * operators.

Prerequisite: Lesson 2

What to look for:

  • Value receivers copy the struct; pointer receivers (*T) modify the original
  • Go auto-dereferences: p.Name works even if p is *Person
  • new(T) allocates zeroed T and returns a pointer — rarely used; prefer &T{} literal
  • Structs are value types — assigning copies the whole struct
🕑 45 min
Lesson 4

Slices, maps, and range

Slice internals (pointer, len, cap), make, append, copy, map CRUD, nil maps, and range loops.

Prerequisite: Lesson 3

What to look for:

  • A slice is NOT an array — it is a view into an underlying array (pointer + len + cap)
  • append may return a new slice if capacity grows — always reassign: s = append(s, val)
  • Reading a missing map key returns the zero value, not an error: use val, ok := m[key]
  • Writing to a nil map panics — always initialise: m := make(map[string]int)
🕑 45 min
Lesson 5

First goroutines and channels

go keyword, sync.WaitGroup, unbuffered channels, buffered channels, and closing channels.

Prerequisite: Lesson 4

What to look for:

  • go f() starts f in a goroutine — the caller continues immediately
  • WaitGroup: Add(n) before launching, Done() in each goroutine, Wait() in caller
  • Unbuffered channel: send blocks until a receiver is ready (and vice versa)
  • Close a channel from the sender to signal "no more values" — never from the receiver
🕑 45 min

How to use this track: Each lesson links to the Go reference pages. Use the reading level tabs (Curious → Exploring → Deep Dive). Practice at go.dev/play — paste and run every code example.

Track quiz

4 questions to check your understanding.

In Go, what does x := 5 inside a function do that var x int = 5 does not?

What happens when you read a key from a Go map that does not exist?

When does a deferred function run?

What does go greet("Alice") do?

Practitioner track →