This is a created article in which the information may have evolved or changed.
We often have headaches due to the uncertainty of incoming parameters, and Golang provides us with access to multivalued parameters to solve this problem. But generally we write the known code directly that all the values know that one is plugged in, but most of us are getting a lot of input from the user to pass through the loop, but this finds that the function of the multivalued parameter cannot be used. In fact, the underlying implementation treats multiple parameters as an array of indefinite lengths passed in. Then we have the idea: since the underlying use of arrays, then we can pass in the array, the conclusion is not possible, or it is reasonable to say: The array can not be directly passed in, need to assist multi-parameter identification to indicate, specifically let us look at the following a simple test:
Func Testmultiparam (t *testing. T) { ValueArray: = []string{"1", "2", "3", "4", "5"} Result: = Valuearray[0:3] t.Log (result) Multiparam (Result ...) Here is the}func multiparam (args ... string) { print (args)} that we normally need to use
So, it is possible to pass in an array, except that it needs to be followed by a "3 point" to represent an array of multiple arguments, so that there is no type exception at the receiving end.