The ellipses (...) (or three dots) operator is used in variadic functions which can be called with any number of trailing arguments.
In the example, we have the Sum function which can accept any number of integer values:
package main
import "fmt"
func main() {
fmt.Println(Sum(1, 2, 3, 4))
fmt.Println(Sum(1, 2, 3, 4, 5, 6))
fmt.Println(Sum(1, 2, 3, 4, 5, 6, 7, 8))
}
func Sum(n ...int) int {
sum := 0
for _, n := range n {
sum += n
}
return sum
}
Output:
10
21
36