关于golang中var()的意思是什么?

时间:2017-02-16 05:56:54

标签: go go-swagger

我通过go-swagger生成的代码,找到以下代码:

// NewReceiveLearningLabActsParams creates a new ReceiveLearningLabActsParams object
// with the default values initialized.
func NewReceiveLearningLabActsParams() ReceiveLearningLabActsParams {
    var ()
    return ReceiveLearningLabActsParams{}
}

我注意到了这里:

var ()

我完全不明白是什么意思,任何人都可以帮我理解这段代码吗?感谢

1 个答案:

答案 0 :(得分:12)

在Go中,这是一个批量定义变量的简写。 您可以使用var声明块,而不必在每个变量声明前面写var。

例如:

var (
    a,b,c string = "this ", "is ","it "
    e,f,g int = 1, 2, 3
)

相同
var a,b,c string = "this ", "is ","it "
var d,e,f int = 1, 2, 3

代码示例中的var ()只是声明没有声明变量。

有关详细信息,请参阅the official Go documentation