Talk: Code Generation with Go - GDG Hamburg Meetup
In June 2022, I gave a 20-minute talk at the GDG Hamburg Meetup about code generation in Go using templates.
The idea is simple: programs are better at repetitive tasks than we are. If you’re writing the same boilerplate over and over, a generator can do it faster and more consistently.
The basic model:
[INPUT] --> [GENERATOR] --> [OUTPUT]
We looked at tools most Go developers already know — go generate, stringer, openapi-generator, the Protobuf compiler — plus things like hugo and helm that generate static sites and Kubernetes manifests from templates.
Most of the talk was hands-on. Starting from stringer (which generates fmt.Stringer implementations for integer types), we built a simple code generator together that automatically implements the String() method for Go types.
All the code is on GitHub. For background, Rob Pike’s article on stringer and Paul Jolly’s GopherCon UK 2019 talk are both worth reading.
We were hiring at MOIA at the time if Go is your thing.
Thanks to everyone who came out. Find me on Twitter or my website.