i:=igolang 官方Effective GOreqreq := reqhttps://golang.org/doc/effective_go#concurrency
req := reqEffective GOreq直接这么看,还是有点拗口。不过不重要, 在了解了 golang 的 区块(block) 定义范围之后, 就迎刃而解了。
Blocks
https://golang.org/ref/spec#Blocks
blockBlocks{}Block 的范围在哪里?
{}universeThe universe block encompasses all Go source text.
universepackageEach package has a package block containing all Go source text for that package.
packagepackagepackage.VariablefileEach file has a file block containing all Go source text in that file.
block目前发现现象,
filename_test.gofilename.gofile block_testmain_test.gomain.gomain.goVarInTestforifswitchEach “if”, “for”, and “switch” statement is considered to be in its own implicit block.
forifswitch{}{}for block(statement block)i:=istatement block同名变量覆盖也就是因为 {} 是 for 子block 的原因, for 的 post 可以修改变量 i, 在 statement 中也可以修改变量 i
loop: 0,1,2,9for blockistatement block_iif blockstatement block_ifor blockiloop: 0-9switch / selectclauseEach clause in a “switch” or “select” statement acts as an implicit block.
switch / selectcase / default:func blockiswitch clause 分支{