After reading the spec, and the “Effective Go” section on them, I still don’t quite understand how interfaces work in Go.
Like, where do you define them? How does interface enforcement work? And is there a way to specify somewhere that an object implements an interface, as opposed to simply defining the methods in the interface?
Apologies for the beginner question; but I really am struggling to understand this.
There are some good posts on interfaces over at Russ Cox and Ian Lance Taylor’s blog which i recommend checking out. They’ll probably cover your questions and more …
I think a good conceptual example is the net package. There you’ll find a connections interface(Conn), which is implemented by the TCPConn, the UnixConn, and the UDPConn. The Go pkg source is probably the best documentation for the Go language.