A Go Puzzle: How can this panic?
Here’s a puzzle for Go developers. How can the following code possibly panic with a nil pointer dereference?
var someThing *SomeStruct // various things happen, including possibly assigning to someThing if someThing != nil && someThing.Body != nil { fmt.Printf("%s", someThing.Body) } Think about it for a minute. I’ll wait.
OK are you done? I don’t want to spoil it for you.
The Answer Here’s the definition of SomeStruct,
type SomeStruct struct { *http.
emoses.org