Multiple Parameters
Go provides a concise way to declare multiple arguments in a function signature when they share the same type.
Type Omission
When multiple arguments are next to each other and have the same type, you only need to declare the type after the last argument in the sequence.
// Instead of this:
func add(x int, y int, z int) int {
return x + y + z
}
// You can write this:
func add(x, y, z int) int {
return x + y + z
}
Mixed Types
This shorthand only works for consecutive parameters of the same type. If the types change, you must specify them.
func addToDatabase(hp, damage int, name string, level int) {
// hp and damage are ints
// name is a string
// level is an int
}