Lesson 02 · Backend & Systems with Go
Go: Structs, Interfaces & Errors
Shape data with structs and methods, choose value or pointer receivers, compose with embedding, satisfy interfaces implicitly, and treat errors as values you wrap, match and extract.
Prerequisites: Go: Fundamentals
Learning objectives
By the end of this lesson, you will be able to:
- Model data with structs whose zero values are usable, built with field-named literals
- Choose value or pointer receivers deliberately and consistently
- Compose types with embedding instead of inheritance
- Define small interfaces (Stringer, io.Writer) and satisfy them implicitly
- Handle errors as values: sentinels, wrapping with %w, errors.Is and errors.As