And*_*rei 2 go data-structures godoc
我在GIN库和Google文档中看到了一段GO代码,如下所示:
type (
T0 []string
T1 []string
T2 struct{ a, b int }
T3 struct{ a, c int }
T4 func(int, float64) *T0
T5 func(x int, y float64) *[]string
)
Run Code Online (Sandbox Code Playgroud)
我不明白的是,该分组在做什么,以及此实现的目的是什么(除非我错过了,否则讨论该主题的文档并不多)
杜松子酒图书馆的另一个例子
type (
RoutesInfo []RouteInfo
RouteInfo struct {
Method string
Path string
Handler string
}
Engine struct {
RouterGroup
HTMLRender render.HTMLRender
allNoRoute HandlersChain
allNoMethod HandlersChain
noRoute HandlersChain
noMethod HandlersChain
pool sync.Pool
trees methodTrees
RedirectTrailingSlash bool
RedirectFixedPath bool
HandleMethodNotAllowed bool
ForwardedByClientIP bool
}
)
Run Code Online (Sandbox Code Playgroud)
最后-抱歉,这是另一个主题,但与此主题相关
var _ IRouter = &Engine{}
Run Code Online (Sandbox Code Playgroud)
为什么在IRouter的_前面有一个?我知道这是一个问题,blank identifier
但在这种情况下有什么目的
代码
type (
A int
B string
)
Run Code Online (Sandbox Code Playgroud)
功能与
type A int
type B string
Run Code Online (Sandbox Code Playgroud)
分组只是组织代码的一种方式。有时使用分组来指示类型以某种方式相关。
在规格中说明了空白标识符的用法:变量分配中空白标识符的目的是什么?。