代码拉取完成,页面将自动刷新
package context
import (
"net/http"
"sync"
)
// Pool is the context pool, it's used inside router and the framework by itself.
//
// It's the only one real implementation inside this package because it used widely.
type Pool struct {
pool *sync.Pool
newFunc func() Context // we need a field otherwise is not working if we change the return value
}
// New creates and returns a new context pool.
func New(newFunc func() Context) *Pool {
c := &Pool{pool: &sync.Pool{}, newFunc: newFunc}
c.pool.New = func() interface{} { return c.newFunc() }
return c
}
// Attach changes the pool's return value Context.
//
// The new Context should explicitly define the `Next()`
// and `Do(context.Handlers)` functions.
//
// Example: https://github.com/teamlint/iris/blob/master/_examples/routing/custom-context/method-overriding/main.go
func (c *Pool) Attach(newFunc func() Context) {
c.newFunc = newFunc
}
// Acquire returns a Context from pool.
// See Release.
func (c *Pool) Acquire(w http.ResponseWriter, r *http.Request) Context {
ctx := c.pool.Get().(Context)
ctx.BeginRequest(w, r)
return ctx
}
// Release puts a Context back to its pull, this function releases its resources.
// See Acquire.
func (c *Pool) Release(ctx Context) {
ctx.EndRequest()
c.pool.Put(ctx)
}
// ReleaseLight will just release the object back to the pool, but the
// clean method is caller's responsibility now, currently this is only used
// on `SPABuilder`.
func (c *Pool) ReleaseLight(ctx Context) {
c.pool.Put(ctx)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。