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 a function returns a err
as second return value, you can use it to catch error
result, err := package.method() if err != nil { log.Printf("error calling package.method: %v", err) }
Parameter
and Type
Syntax(i item)
is stating that function process()
operates on an object of type item
item
is a struct defineditem
is used via item.id
and item.price
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 }