Unpacking arguments in Go
You can define Go functions to accept a variable number of arguments using ...
before the parameter type. Inside the function the arguments are treated as a slice. For example:
func printNums(nums ...int) {
for i := range nums:
fmt.Println(i)
}
To unpack a slice as arguments when calling a function, you can use ...
after the slice. For example:
nums := []int{1,2,3,4,5,6,7,8}
printNums(nums...)