type handler struct {
p sync.Pool
}
func newHandler() *handler {
h := &handler{}
h.p.New = func() interface{} {
return &Context{}
}
return h
}
func main (){
ctx := h.p.Get().(*Context)
defer h.p.Put(ctx)
}
1.上面这段代码中 h := &handler{}
这一行的意思是不是生成一个 hander 对象并将地址赋值给 h?
2.代码中的 return &Context{}
是不是会生成一个 context 的对象并将这个对象的地址放到缓存池?
3.这个 Context 就是普通的 struct吗? 还是go 语言中的保留字符?
已经找到答案....真是自问自答赚积分= - =。context 也是一个自己定义的struct ,并且go 中没法不声明就这样初始化一个context