typeover
go curriculum

Curriculum Errors & packaging

module 5 of 7

Errors & packaging

Go's distinctive error convention — the (T, error) return shape, errors.Is and errors.As for inspection, and the rest of how Go programs are organised into packages and modules.

Themes

Go has no exceptions for ordinary control flow. Errors are values returned alongside results — (T, error). The caller checks err != nil and decides. This feels noisy at first;…

9 ready

begin →

Inspecting errors without breaking the wrap chain. errors.Is(err, target) walks the wrap chain looking for a match against a sentinel. errors.As(err, &target) walks looking for…

9 ready

begin →

v.(T) asserts that an interface value v is actually of type T. Panics if wrong. Use the comma-ok form to check first: if t, ok := v.(T); ok { ... }. For multi-branch checks…

9 ready

begin →

Every file declares a package: package foo. Names starting with a capital letter are exported; lowercase are package-private. This rule is mechanical and pervasive; once you…

9 ready

begin →

A module is a versioned collection of packages — your project's unit of dependency. go mod init github.com/you/yourthing produces go.mod. go get adds deps. Module paths look…

9 ready

begin →