I am learning Go and am trying to fully understand how to use interfaces in Go.
In the book The Way to Go, there is an example listing 11.1 (pages 264-265). I feel that I am definitely missing something in my understanding of it. The code runs fine, but I do not understand what effect (if any) the interface is having on the struct and method.
package main
import "fmt"
type Shaper interface {
Area() float32
}
type Square struct {
side float32
}
func (sq *Square) Area() float32 {
return sq.side * sq.side
}
func main() {
sq1 := new(Square)
sq1.side = 5
// var areaIntf Shaper
// areaIntf = sq1
// shorter, without separate declaration:
// areaIntf := Shaper(sq1)
// or even:
areaIntf := sq1
fmt.Printf("The square has area: %f
", areaIntf.Area())
}