[Golang] Pass Slice or Array to Variadic Function


What is ... in Go Function Parameter? [2]

dot dot dot (...) in final parameter of Go function means you can pass zero, one, or more arguments for that parameter according to Function types in Go spec, and the function of such kind is usually called variadic function.

For example, assume we have the following function:

func giveMeString(s ...string)

We can invoke the function by:

giveMeString()
giveMeString("hello")
giveMeString("hello", "world")

The function can be invoked with more string arguments as you like. You can run above example in Go Playground to fiddle the code by yourself.

One more well-known example is fmt.Println in Go Standard library. You can also try it in Go Playground.