Casting Go interface to struct
Learning to think in Go
I was using an excellent go icmp library recently. I got hung up on dealing with a received MessageBody type that I knew was really an Echo type, but I could not refer to the fields in the Echo
struct. I think my C/C++/Python background got in my way here.
After a bit of head scratching, I noticed the MessageBody
type was defined an . . .
Posted in: go
Simple defer'd Error Handling in Go
I recently wrote a Go func that starts off by opening a network listening connection and defers closing that connection.
connection, err := icmp.ListenPacket(...)
if err != nil {
panic(err)
}
defer connection.Close()
The defer'd connection.Close()
returns an error, but how to capture and do something with that . . .
Posted in: go