Methods in Go
From the Go cheat sheet · Functions · verified Jul 2026
Methods
Methods on types and interfaces
go
type Rectangle struct {
Width, Height float64
}
// Value receiver
func (r Rectangle) Area() float64 {
return r.Width * r.Height
}
// Pointer receiver
func (r *Rectangle) Scale(factor float64) {
r.Width *= factor
r.Height *= factor
}📦 Methods attached to types with receivers
🔄 Value receivers can't modify, pointer receivers can
🎯 Go auto-dereferences and takes addresses
⚡ Methods can be on any type, not just structs