Skip to main content

Interfaces

Interfaces in Golang are like duck typing. No keyword says a struct implements an interface. The compiler decides by the methods on the type.

Interface as function arguments

Say a function takes an interface type as an argument. Then the implementing type is copied into the interface variable.

  1. If you pass a pointer, the struct's pointer is copied into the interface variable.
  2. If you pass a value, the value is copied into the interface variable.
Interface value isn't mutable

Once the value is set, you can't change it or the reference in the interface.