Problem Statement
A production bug at Cloudflare caused a nil pointer panic despite a nil check passing. The root cause was Go's interface implementation. Explain the internal structure of interfaces and the infamous "nil interface" trap.
Interface Internal Structure
The Nil Interface Trap
Why This Happens
The Fix
Interface Conversion Cost
Type Assertions vs Type Switches
Follow-up Questions
- What's the overhead of an interface method call vs direct call?
- Can a value receiver satisfy an interface expecting a pointer receiver?
- How does Go determine interface satisfaction at compile time?