This is a creation in Article, where the information may have evolved or changed.
For detailed usage, please refer to "Go Language Programming" (Xu Xiwei, Beijing: People's post and Telecommunications Press, 2012.08) Section 2.5.3 "Indeterminate parameters".
Here are some of the experiences that I use:
You can interpret an indeterminate parameter as an array, you can organize an array or slice yourself, and then pass it as an indeterminate parameter to a function that accepts indeterminate arguments.
Assuming that there is another variable called myfunc3 (args ... int), the following shows how to organize an indeterminate parameter yourself:
Func myfunc (arg1 int,arg2 int, args ... int) {
Argsnew: =make ([]int,2+len (args)
Argsnew[0]=arg1
Argsnew[1]=arg2
For I:=0;i<len (args); i++ {
Argsnew[i+2]=args[i]
}
Myfunc3 (Argsnew ...) Note that you must add "..." to indicate that an indeterminate parameter is being transmitted instead of an array
}
Reference article:
See Paradigm Golang (14)-variadic function: Http://ieqi.net/2013/03/11/%E7%9C%8B%E8%8C%83%E4%BE%8B%E5%AD%A6-golang-%EF%BC%88%E5%8D %81%e5%9b%9b%ef%bc%89-%e5%8f%af%e5%8f%98%e5%8f%82%e6%95%b0%e5%87%bd%e6%95%b0/