I would like to implement a version errors.Newthat takes the same parameters as fmt.Sprintf. For this, I wrote the following function:
func NewError(format string, a ...interface{}) error {
return errors.New(fmt.Sprintf(format, a))
}
However, ait becomes the only parameter of the array inside NewError(), thereby causing Sprintf()only one parameter to be filled in the format string. How can I make ainterpreted as a variable number of arguments?
source
share