thecodex.expert · The Codex Family of Knowledge
Track 2 — Practitioner

Go: Practitioner

Five lessons: interfaces, concurrency patterns, error wrapping, context, and building HTTP APIs.

🕐 ~4 hours5 lessonsGo 1.23

Lessons

Lesson 1

Interfaces and implicit satisfaction

Interface definition, implicit satisfaction (no implements), type assertions, type switches, and embedding.

What to look for:

  • No implements keyword — the compiler checks method sets
  • The io.Reader / io.Writer pattern: accept interfaces, return structs
  • Type switch: the idiomatic way to branch on dynamic type
  • Embedding composes types — it is not inheritance
🕑 50 min
Lesson 2

Concurrency patterns: select, pipelines, fan-out

select statement, pipeline pattern, fan-out/fan-in, done channels, and goroutine leak prevention.

Prerequisite: Foundations Track

What to look for:

  • select: blocks until one case is ready; random choice if multiple ready
  • Pipeline: each stage is a goroutine with input and output channels
  • Always provide a way for goroutines to stop — done channel or context
  • Goroutine leaks: goroutines stuck waiting on channels that will never fire
🕑 50 min
Lesson 3

Error handling: wrapping, Is, and As

Custom error types, fmt.Errorf with %w, errors.Is for sentinel errors, errors.As for concrete types, and panic vs error.

Prerequisite: Lesson 1

What to look for:

  • %w wraps the error in the chain — enables errors.Is/As to traverse it
  • errors.Is for sentinel values (var ErrNotFound = errors.New(...))
  • errors.As for extracting structured error info (field, code, path)
  • Wrap errors with context: fmt.Errorf("processUser %q: %w", name, err)
🕑 45 min
Lesson 4

Context: cancellation, deadlines, and values

context.Background, WithCancel, WithTimeout, WithDeadline, ctx.Done(), ctx.Err(), and passing context through a call chain.

Prerequisite: Lesson 2

What to look for:

  • Always pass context as the first argument: func DoWork(ctx context.Context, ...)
  • Always call cancel() — even if the context times out naturally
  • ctx.Done() returns a channel — use it in select to stop work
  • Do not store contexts in structs — pass them explicitly every call
🕑 45 min
Lesson 5

net/http and encoding/json

HTTP server with HandleFunc, JSON marshaling with struct tags, reading request bodies, setting headers, and handling errors in handlers.

Prerequisite: Lessons 3–4

What to look for:

  • Every request is handled in its own goroutine — handlers must be concurrent-safe
  • json struct tags: json:"name" controls the JSON key; omitempty skips zero values; "-" never serialises
  • Always set Content-Type before WriteHeader — headers can't change after body starts
  • http.Error() is shorthand for writing an error status + plain text body
🕑 50 min

How to use this track: Each lesson links to the deep-dive reference pages. Practice at go.dev/play. For the HTTP lessons, install Go locally and run the server — the browser interaction makes it concrete.

Track quiz

4 questions to check your understanding.

How does a type in Go satisfy an interface?

What does fmt.Errorf("op %w", err) do compared to fmt.Errorf("op %v", err)?

What must you always do after calling context.WithCancel or context.WithTimeout?

In a Go HTTP handler, when does each request get a goroutine?

← FoundationsAdvanced track →