In Go, type and interface are related but serve different purposes. Let’s break it down:
typeNew basic type:
type MyInt int
Struct type:
type Person struct {
Name string
Age int
}
Function type:
type Adder func(a, b int) int
Interface type:
type Speaker interface {
Speak() string
}
Notice that interface itself is defined via type.
interface