Allowing for a variable number of return values in method declaration
<p>I have a function that solves the problem of Go not allowing for the setting of default values in method declarations. I want to make it just a little bit better by allowing for a variable number of return variables. I understand that I can allow for an array of interfaces as a return type and then create an interface array with all the variables to return, like this:</p>

<pre><code>func SetParams(params []interface{}, args ...interface{}) (...[]interface{}) {
    var values []interface{}
    for i := range params {
            var value interface{}
            paramType := reflect.TypeOf(params[i])
            if len(args) &lt; (i + 1) {
                    value = params[i]
            } else {
                    argType := reflect.TypeOf(args[i])
                    if paramType != argType {
                            value = params[i]
                    }
                    value = args[i]
            }
            values = append(values, value)
    }

    return values
}
</code></pre>

<p>This is an example of a method you want to define default values for. You build it as a variadic function (allowing a variable number of parameters) and then define the default values of the specific params you are looking for inside the function instead of in the declaration line.</p>

<pre><code>func DoSomething(args ...interface{}) {
    //setup default values
    str := "default string 1"
    num := 1
    str2 := "default string 2"


    //this is fine
    values := SetParams([]interface{str, num, str2}, args)
    str = values[0].(string)
    num = values[1].(int)
    str = values[2].(string)


    //I'd rather support this
    str, num, str2 = SetParams(params, args)
}
</code></pre>

<p>I understand that </p>

<blockquote>
  <p>[]interface{str, num, str2}</p>
</blockquote>

<p>in the above example is not syntactically correct. I did it that way to simplify my post. But, it represents another function that builds the array of interfaces.</p>

<p>I would like to support this:</p>

<pre><code>str, num, str2 = SetParams(params, args)
</code></pre>

<p>instead of having to do this:</p>

<pre><code>values := SetParams([]interface{str, num, str2}, args)
str = values[0].(string)
num = values[1].(int)
str = values[2].(string)
</code></pre>

<p>Any advice? Help?</p>