go - What't the means about var () in golang

ID : 274476

viewed : 75

Tags : gogo-swaggergo





Top 2 Answer for go - What't the means about var () in golang

vote vote

95

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.

vote vote

83

Top 3 video Explaining go - What't the means about var () in golang







Related QUESTION?