小白请问go花括号什么情况 下可以写在一行?

taatcc · · 2346 次点击
> One consequence of the semicolon insertion rules is that you cannot put the opening brace of a control structure (`if`, `for`, `switch`, or `select`) on the next line. If you do, a semicolon will be inserted before the brace, which could cause unwanted effects.
#4
更多评论
```go func TestName(t *testing.T) { testF := func() { } if 1 == 1 { } } ``` go 不允许`{`换行写,例如上述的。`}`都可以。 这处的设计是基于 `{` 在其他语言中通常换行与不换行都行,go强制做了规定。
#1