我有一个方法,它的参数是v ...interface{}
,我需要在这个切片之前添加一个string
。以下是这个方法:
func (l Log) Error(v ...interface{}) {
l.Out.Println(append([]string{" ERROR "}, v...))
}
当我尝试使用append()
时无法运行:
> append("some string", v)
first argument to append must be slice; have untyped string
> append([]string{"some string"}, v)
cannot use v (type []interface {}) as type string in append
在这种情况下,正确的前置方式是什么?
v ...interface{}
作为参数的方法。 - Volker