23

I go though the code generated by go-swagger, found follow code:

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

I noticed here:

var ()

I totally not understand what's the means, could anyone help me understand this code? thanks

fisafoer
  • 273
  • 1
  • 2
  • 6

1 Answers1

47

In Go this is a shorthand for defining variables in bulk. Instead of having to write var in front of every variable declaration, you can use a var declaration block.

For example:

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

is the same as

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

The var () in your code example simply states that no variables were declared.

Refer to the official Go documentation for more information.

Marco
  • 1,080
  • 1
  • 12
  • 13