Inception, Go programs that generate Go code
summary
Shows concrete techniques: use go/types (not just go/ast) to resolve embedded interfaces so mocks really implement everything, drive generators with go generate, and replace hand-written plumbing like testify assertions with a 240-line generator. Reports mapstructure cost 61 allocations; switching to generated marshal code removes those allocations and drops a 9.5µs operation down to ~117ns. Mentions mockery, gofmt/goimports, templates, and tests generated to keep code in sync.
AI-written summary · about
chapters (12)
- 0:00Introduction to code generation
- 2:18Generating Go code from structured data
- 5:55Modifying existing Go code
- 8:21Parsing Go code to generate Go code
- 13:44Using go generate for automation
- 17:20Managing generated code and templates
- 21:57Generating boilerplate in testify
- 25:10Generating convenience wrappers
- 28:44Performance with mapstructure
- 31:59Generating tests for generated code
- 32:43Domain-specific languages in Go
- 35:11Summary and closing
