Go

Notes on the Go programming language — interfaces, concurrency, testing, and patterns that have held up in production.

Go 1.24's "tool" directive

Pin tool versions in Go 1.24 with the new 'tool' directive. Replace tools.go pattern with native go.mod support for project tooling.

Capturing console output in Go tests

Test functions that write to stdout/stderr in Go by capturing output with os.Pipe. Learn patterns to avoid deadlocks in concurrent tests.

Three flavors of sorting Go slices

Compare three Go slice sorting methods: sort.Interface, sort.Slice with closures, and modern generic slices.Sort with type safety.

Nil comparisons and Go interface

Debug tricky nil comparisons in Go interfaces. Understand dynamic types, type assertions, and use reflect for generic nil checking.

Go slice gotchas

Avoid common Go slice mistakes: shared backing arrays, nil vs empty slices, append behavior, and slice copying pitfalls explained.

Topological sort

Implement topological sorting in Go to order tasks by dependencies. Process directed acyclic graphs for build systems and scheduling.

Writing a circuit breaker in Go

Build a production-ready circuit breaker in Go from scratch with closed, open, and half-open states to prevent cascading failures.

Dysfunctional options pattern in Go

Discover a simpler alternative to functional options: method chaining with builder-style configuration that's 76x faster and easier to understand.

Strategy pattern in Go

Replace inheritance with the Strategy pattern in Go using interfaces. Achieve composable, testable code without class hierarchies.

Anemic stack traces in Go

Learn how to build custom error types in Go to create stack traces without runtime overhead, inspired by Rob Pike's Upspin error handling.