I have the following code to print n lines for debug purposes. output() prints the address of args instead of the parameters. How to fix it ?
var outputMax = 10
var outputCnt = 0
func output(args ...interface{}) {
outputCnt++
if(outputCnt < outputMax) { println(args) }
}
func main() {
for i := 0; i < 5; i++ {
output("Value of i is now:", i)
}
}
The usual way to call a varargs function would be like so:
func output(args ...interface{}) {
println(args...)
}
However, this will give you a invalid use of ... with builtin println
compilation error. If you switch to fmt.Println()
instead, it should work.