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
Short Variable Declaration Operator(:=) in Golang is used to create the variables having a proper name and initial value. The main purpose of using this operator to declare and initialize the local variables inside the functions and to narrowing the scope of the variables.
Multiple variables can be declared using a single statement. var name1, name2 type = initialvalue1, initialvalue2 is the syntax for multiple variable declaration. The type can be removed if the variables have an initial value. Since the above program has initial values for variables, the int type can be removed.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With