Go Functions
Functions are the central building blocks in Go.
1. Basic Function
Here's a function that takes two ints and returns their sum as an int. Go requires explicit returns.
When multiple consecutive parameters are of the same type, you can omit the type for all but the last one: func plus(a, b, c int) int.
2. Multiple Return Values
Go has built-in support for multiple return values. This feature is used often in idiomatic Go, for example, to return both result and error values from a function.
3. Variadic Functions
Variadic functions can be called with any number of trailing arguments. For example, fmt.Println is a common variadic function.
In mathematics and in computer programming, a variadic function is a function of indefinite arity, i.e., one which accepts a variable number of arguments. Support for variadic functions differs widely among programming languages.
4. Anonymous Functions and Closures
Go supports anonymous functions, which can form closures.