Inception: Go programs that generate Go code
summary
Shows techniques for reducing boilerplate in Go by writing programs that generate Go source code. Covers multiple approaches to building code generators for Go programs, illustrating how to produce the repetitive code automatically.
AI-written summary · about
chapters (27)
- 0:00Intro
- 0:33and the stdlib is amazing
- 1:21reducing boilerplate
- 1:55Parsing data to generate Go code
- 4:17Modifying Go code
- 4:38a big part of Go's brilliant tooling
- 5:04powered by the stdlib
- 5:23import "go/scanner" import "go/parser" // read and parse to source code
- 6:02import "go/printer" // generating code from AST nodes
- 6:32Parse Go code to generate Go code
- 7:49generating mocks
- 9:53$ go generate
- 12:03go/ast provides very raw data
- 13:19generating any mock
- 14:34tens of assertion helpers
- 15:363 boilerplate functions per each assertion
- 16:48go/types go/doc
- 17:24codegen: 239 lines of code removed: 839 lines of code
- 19:35avoid goimports on generated code
- 20:25Generating decoders
- 21:02import "reflect"
- 22:31Read code Analyze code Generate code and tests
- 23:19Go DSLS (Domain-Specific Languages)
- 24:41How does goa do it?
- 24:54Magic
- 25:37you can reduce boilerplate
- 25:52stdlib has great packages to build your own tools








