This question already has an answer here:
In Go I can use the underscore to ignore a return value from a function that returns multiple values. For instance:
res, _ := strconv.Atoi("64")
Suppose I wanted to use the first value directly into another function call (while ignoring error checking best practices, in this example):
myArray := make([]int, strconv.Atoi("64"))
The compiler will complain that I'm using a multiple-value function in a singe-value context:
./array-test.go:11: multiple-value strconv.Atoi() in single-value context
Is it possible to "pick and choose" from the return values in a single-line without resorting to auxiliary functions?
</div>
The only real way to do it is to create some utility "bypass" function, and since this is Go, you'll have to declare one per type.
for example:
func noerrInt(i int, e err) int {
return i
}
then you can do:
myArray := make([]int, noerrInt(strconv.Atoi("64")))
But really, this pretty much sucks, AND ignores best practices.