func HelloWorld() string { return "Hello World" }
HelloWorld
string
typefunc add(x int, y int) int { return x + y }
add
x
which is of type int
y
which is also of type int
int
When you have multiple return values on a function, it must be wrapped in a parenthesis ()
func twoReturns() (r1 string, r2 string) { // ... }
When a function returns a err
as second return value, you can use it to catch error
// package.method() has two return values result, err := package.method() if err != nil { log.Printf("error calling package.method: %v", err) }
Parameter
and Type
BreakdownFirst parameter is stating that function operates on an object of defined name and type
item
is a struct defineditem
is used via item.id
and item.price
fx
would be made availablefunc (m_mod *MathModule) FunctionName() () { arithmatics := m_mod.arithmatics }
process()
is the name of the function with standard parameter
(string, int)
states that the function has multiple return values of string
and integer
types
func (i item) process() (string, int) { return i.id, i.price } // above the file type item struct { id string price int }