These are chat archives for gin-gonic/gin

1st
Mar 2019
sgon00
@sgon00
Mar 01 01:53

Hi, I am new to golang and gin. When I read the gin README, I don’t really understand why using blocks here:

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

why not simply do the following?

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

There are also blocks in this example:

authorized.Use(AuthRequired())
{
    authorized.POST("/login", loginEndpoint)
}

Thanks a lot.

Michael Aldridge
@the-maldridge
Mar 01 02:43
@sgon00 its cosmetic
since go is a machine formatted language, you need the block there if you want to jog in
sgon00
@sgon00
Mar 01 02:46
@the-maldridge thanks for the reply, but I don’t quite understand your words...
Michael Aldridge
@the-maldridge
Mar 01 02:50
perhaps you can explain what you don't understand
sgon00
@sgon00
Mar 01 03:07
@the-maldridge To explain what I don’t understand in my question? or To explain what I don’t understand in your words?
What I don’t understand in my question is I don’t know why I should use block here because without it, the code can still be run. What benefit to use block?
What I don’t understand in your words is I don’t understand them at all (I mean completely). Sorry that I am not a native English speaker. To be more specific, when I check dictionary, cosmetic means girl’s toiletry. I don’t know what girl’s toiletry to do here. And jog in means running slowly. I don’t know if you mean adding block here will make go run much slower than without it or not.
Sorry that if I sound funny or not “good”. I don’t really mean it. I am just trying to answer your question.
Michael Aldridge
@the-maldridge
Mar 01 03:09
the use of the braces is that it means the contents of the braces will be moved in one tab stop. In a large file of many routes with many route groups, this can dramatically improve readability
you can run the code without the braces because they have no syntactic meaning in this case; they are only present to provide formatting that is easier to read
sgon00
@sgon00
Mar 01 03:11
@the-maldridge Thank you very much for this explanation. I can understand this completely now. So all it’s just for readability. I was confused a lot for a whole day (even googled it) before asking here. Thanks a lot again. ^_^
Michael Aldridge
@the-maldridge
Mar 01 03:12
np