Variadic functions receive the arguments as a slice of the type. In this case your function receives a []interface{}
named args
. When you pass that argument to fmt.Sprintf
, you are passing it as a single argument of type []interface{}
. What you really want is to pass each value in args
as a separate argument (the same way you received them). To do this you must use the ...
syntax.
str := fmt.Sprintf(format, args...)
This is also explained in the Go specification here.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…