这是一个块参数吗?

I started learning Gin recently and in the README file comes the following code:

v1 := router.Group("/v1")
{
    v1.POST("/login", loginEndpoint)
    v1.POST("/submit", submitEndpoint)
    v1.POST("/read", readEndpoint)
}

I readed the source code for the method Group and is like this:

IRouter interface {
    IRoutes
    Group(string, ...HandlerFunc) *RouterGroup
}

Maybe I'm misunderstanding the syntaxis or missing something in the code (Im pretty new in Go) but it looks like it is passing a block as the second argument, is this possible in Go?

The block you see in { ... } is just that, a code block, not an argument to anything. The Group method is variadic, and could accept any number of HandlerFunc arguments, but nothing is passed in here.

Since Go is block scoped, you can use blocks to create a limited variable scope. Since there are no declarations within the blocks, I see no use for this pattern here other than to cause the HandlerFunc assignments to be indented as a group for style reasons.

An example showing the scope of a code block:

http://play.golang.org/p/Kgpw1zCC7X

x := 42

{
    x := 3
    y := 4
    fmt.Println("x inside block:", x) // prints 3
}

fmt.Println("x outside block:", x) // prints 42
// fmt.Println(y) // undefined: y

The Group function of IRouter is a variadic function. It means it can be called with any number of trailing arguments, of type HandlerFunc.

Another example of this type of function in go is fmt.Println:

Its signature is:

func Println(a ...interface{}) (n int, err error)

so you can invoke it with a variable number of arguments:

fmt.Println(1, 2) fmt.Println("a" , "b" , "C")