Essential Go Functions  Edit on GitHub      File Issue

Parameters

A function can optionally declare a set of parameters:

func SayHelloToMe(firstName, lastName string, age int) {
	fmt.Printf("Hello, %s %s!\n", firstName, lastName)
	fmt.Printf("You are %d", age)
}

func main() {
	SayHelloToMe("John", "Doe", 35)
}
Hello, John Doe!
You are 35

Notice that the type for firstName is omitted because it is identical to lastName.

  ↑ ↓ to navigate     ↵ to select     Esc to close