You define methods on types in Go by declaring a function with a receiver argument that matches the type name. The receiver appears in parentheses between the func keyword and the method name.
type MyType struct {
Value int
}
func (m *MyType) Double() int {
return m.Value * 2
}
Use a pointer receiver (*MyType) if the method needs to modify the struct's fields; use a value receiver (MyType) if it only reads data.