我去go-swagger生成的代码,找到以下代码:
// NewReceiveLearningLabActsParams creates a new ReceiveLearningLabActsParams object
// with the default values initialized.
func NewReceiveLearningLabActsParams() ReceiveLearningLabActsParams {
var ()
return ReceiveLearningLabActsParams{}
}
Run Code Online (Sandbox Code Playgroud)
我注意到了这里:
var ()
Run Code Online (Sandbox Code Playgroud)
我完全不明白是什么意思,任何人都可以帮我理解这段代码吗?谢谢
小智 17
在Go中,这是批量定义变量的简写.您可以使用var声明块,而不必在每个变量声明前面写var.
例如:
var (
a,b,c string = "this ", "is ","it "
e,f,g int = 1, 2, 3
)
Run Code Online (Sandbox Code Playgroud)
是相同的
var a,b,c string = "this ", "is ","it "
var d,e,f int = 1, 2, 3
Run Code Online (Sandbox Code Playgroud)
在var ()你的代码示例只是说,没有变量声明.
有关更多信息,请参阅Go官方文档.