Q:
Method vs Functions in Golang, what's difference?
A:
Method
:
define the behavior of a type
should use state
logically connected
For example:
type Something struct{ name string } func (s Something) Name() string { return s.name }
Function
:
should be stateless
can accept interface as input
For example:
type Something interface { Name() string } func GetName(s Something) string { return s.Name() }