A variadic parameter must be last; it collects arguments into a slice inside the function.
func sum(nums ...int) int {
total := 0
for _, n := range nums {
total += n
}
return total
}
sum(1, 2, 3)
Use ... after the slice to expand it.
xs := []int{1, 2, 3}
sum(xs...)
The slice is passed without copying underlying elements (same backing array semantics as usual slices).
Go has no keyword arguments. Use structs, functional options, or named parameters via a config struct.
type Params struct{ Timeout time.Duration; Retries int }
func Do(p Params) error { return nil }
fmt.Println accepts ...any (formerly ...interface{}). Each value is passed as any with dynamic type preserved.