When 'nil' Isn't
One sunny Monday afternoon, our crash reporting alerted us to an error instantly recognizable by any Go programmer.
Strange, I thought. But perhaps the type isn’t nil, the value is, and perhaps an extra nil check will fix the code.
The Briefest Introduction To Interfaces
Let’s look again at the problematic switch statement.
How did this happen?
You may not have seen a typed-but-nil interface before, and understandably so. They’re not easy to create without either using the reflect package, or playing with the internal representation of Go variables.
So there you have it. In Go, sometimes variables are not as nil as they appear.
I put together a piece of sample code so that you can play with this yourself. You can find it on GitHub.
We are hiring backend engineers (Go experience not required): email us at firstname.lastname@example.org to learn more!