Go
Channels, errors, context and the Go runtime.
The course
Open the courseStart at 01. The first lesson names the types. The next one builds an object. Each sample is on the page.
-
Skill
Basics
The types, explained, then an object you can name and call.
-
01
Go from zero: a name has a type
Start here
A Go name has a type. name is a string, cents is an int, and ready is a bool. The program prints latte $4.50 ready.
Adds The types this course uses
-
02
Go from zero: a struct is the object
A struct groups named fields, and a method is a function on that struct. Item holds a drink and a price in cents, and Label prints latte $4.50.
Adds An object you can name and call
-
01
Go from zero: a name has a type
Start here
-
Practice
Tips
A rule that prevents a bug, then a program that uses the object.
-
03
Go from zero: zero is a real value
A var with no value is not empty of meaning. A blank order has an empty name and 0 cents. The program prints "" $0.00.
Adds A tip that prevents a bug
-
04
Go from zero: make the map before you write
A map has to be made before a write. map[string]int{} makes a menu. The program stores 450 under latte and prints 450.
Adds A program that uses the object
-
03
Go from zero: zero is a real value
-
Further
A whole program
One more idea, then a program that puts the pieces together.
-
05
Go from zero: a method can change the struct
A method with a pointer receiver changes the struct the caller holds. AddTip adds 20 percent to a $4.50 bill, and the program prints $5.40.
Adds A program that puts the pieces together
-
06
Go from zero: an interface is a method list
An interface names the methods a function needs. Labeller asks for Label, Item has Label, and show prints latte $4.50.
Adds A program that puts the pieces together
-
05
Go from zero: a method can change the struct
GoByte Skills: Go track, 3 lessons. Channels, error wrapping and context: how Go makes concurrency and failure explicit.
Open the Go trackArticles
RSS-
Context: cancel the parent, the children hear it
GoByte Skills #3: One cancel() at the root closes Done on every context below it, and closing a channel wakes every waiter at once. Context is a tree, not a kill switch. Also: why a dropped stop() leaks.
-
errors.Is: wrap it, keep the cause
GoByte Skills #2: %v prints the exact same message and quietly drops the chain. %w keeps it, and errors.Is walks it link by link, so the cause survives every layer of context.
-
Go channels: the queue that says no
GoByte Skills #1: A buffered channel is a bounded queue. When it is full, the send parks until there is room, so the slow consumer sets the pace. Backpressure in one argument to make(), plus the exact order a real run prints.