Read More Go Code!
People often give the advice “the best way to get better at any programming language is to write more programs”. This is true at the start, but as you begin to get more comfortable with the language, the best way to improve is to read lots of other people’s code too.
Every week for 30 minutes I will find a repo on Github and just read it. I tend to start with the entry point (usually main.go) and look for interesting patterns and ideas to see what I can learn from them. Here are some of my favourites:
-
https://github.com/google/exposure-notifications-server. This was reference server co-authored by Apple and Google during Covid. The way they use the logger inspired the way I have logged ever since. It also looks very similar to Slog that just got released.
-
https://github.com/matryer/xbar by Mat Ryer.This one is really interesting as its just a completely different way to use go.
-
https://github.com/ardanlabs/service by Ardan Labs. The Ardan Labs folk run a whole course on how to write this service but kindly make it open source and free. It has examples of tracing, logging, profiling and much more. A really great place to learn.
-
https://github.com/charmbracelet/bubbletea yields incredibly beautiful TUIs, and does some interesting things with Go to achieve it.
-
https://github.com/Humpheh/goboy a Frigging GameBoy emulator written in Go!
The sheer variety of ways Go can be used is amazing, and you’ll discover new patterns as you read them.
Try spending 30 minutes reading more Go code every week for the next month and let me know how you get on.