typeover
curriculum

Curriculum Idioms & ecosystem

module 7 of 7

Idioms & ecosystem

Graduating to "real Go" — defer, embedding, context, testing, the small-interface idiom, project layout, and the gotchas every Go programmer learns the hard way.


themes

defer fn() schedules fn to run when the surrounding function returns. The closest TS analogue is a try/finally you don't have to indent. Multiple defers run LIFO. **Arguments…

9 ready begin →

Struct embedding gives you composition without inheritance. Embed a type as an unnamed field and its methods get promoted onto the outer struct. This is how Go does "extend a type"…

9 ready begin →

context.Context propagates cancellation, deadlines, and request-scoped values across goroutines and API boundaries. By convention, the first argument of any function that does I/…

9 ready begin →

Go has a testing package in the standard library. Tests live next to code in _test.go files. The pattern is table-driven: a slice of (name, input, want) tuples plus `t.Run(…

9 ready begin →

io.Reader { Read(p []byte) (n int, err error) }. One method. Go interfaces are typically tiny because implicit satisfaction rewards it — small interfaces are easy to satisfy acci…

9 ready begin →

cmd/<binary-name>/main.go per binary; internal/... for packages that should not be importable by other modules. Outside those two conventions, layout is up to you. The `golang-…

9 ready begin →

The "what bit me in code review" survival kit: - Loop variable capture (Go 1.22+ helped, but you should still know). - Nil interface vs nil concrete (a non-nil pointer inside an…

9 ready begin →