Go Structs and Methods
Go has no classes. A struct groups named fields, and a method is a function with a receiver written before its name. func (r Rect) Area() int means Area can be called on any Rect value.
Go
package main
import "fmt"
type Rect struct {
Width, Height int
}
func (r Rect) Area() int {
return r.Width * r.Height
}
func main() {
r := Rect{Width: 3, Height: 4}
fmt.Println(r.Area())
}