Methods can only be defined on named types. They cannot be defined on unnamed types such as
[]int or map[string]int.A named type is any type that is declared using the type keyword and given its own name.Method Syntax
receiver: The variable that represents the instance the method is called on.ReceiverType: The type the method is attached to.MethodName: The name of the method being defined.parameters: The input arguments the method accepts (optional).returnType: The value type the method returns (optional).
Define and Call Methods
Define
Call
Pointer Receivers
To allow a method to modify the original data in types that use
pass-by-value (fully independent types) semantics, the method must use a pointer receiver.