function go code example
Example 1: go functions
func functionName() {}
func functionName(param1 string, param2 int) {}
func functionName(param1, param2 int) {}
func functionName() int {
return 42
}
func returnMulti() (int, string) {
return 42, "foobar"
}
var x, str = returnMulti()
func returnMulti2() (n int, s string) {
n = 42
s = "foobar"
return
}
var x, str = returnMulti2()
Example 2: go functions
package main
import "fmt"
func add(int x, int y) int {
return x + y
}
func main() {
fmt.Println(add(42, 13))
}
Notice that the type comes after the variable name