refactor(variable): 简化变量池函数
- PoolGet() 改为调用 NewContext() - PoolPut() 改为调用 ReleaseContext() - 添加 Deprecated 文档注释 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
4d608c4284
commit
4a93cf2b5c
@ -40,23 +40,10 @@ func GetPool() *sync.Pool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// PoolGet 从池中获取 Context(包装方法,用于统计)
|
// PoolGet 从池中获取 Context(包装方法,用于统计)
|
||||||
|
//
|
||||||
|
// Deprecated: 使用 NewContext 代替,该函数保持向后兼容。
|
||||||
func PoolGet(ctx *fasthttp.RequestCtx) *Context {
|
func PoolGet(ctx *fasthttp.RequestCtx) *Context {
|
||||||
vc := pool.Get().(*Context)
|
vc := NewContext(ctx)
|
||||||
|
|
||||||
// 初始化
|
|
||||||
vc.ctx = ctx
|
|
||||||
vc.status = 0
|
|
||||||
vc.bodySize = 0
|
|
||||||
vc.duration = 0
|
|
||||||
vc.serverName = ""
|
|
||||||
|
|
||||||
// 清空缓存和自定义变量
|
|
||||||
for k := range vc.cache {
|
|
||||||
delete(vc.cache, k)
|
|
||||||
}
|
|
||||||
for k := range vc.store {
|
|
||||||
delete(vc.store, k)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 更新统计
|
// 更新统计
|
||||||
statsMu.Lock()
|
statsMu.Lock()
|
||||||
@ -68,19 +55,14 @@ func PoolGet(ctx *fasthttp.RequestCtx) *Context {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// PoolPut 将 Context 放回池中(包装方法,用于统计)
|
// PoolPut 将 Context 放回池中(包装方法,用于统计)
|
||||||
|
//
|
||||||
|
// Deprecated: 使用 ReleaseContext 代替,该函数保持向后兼容。
|
||||||
func PoolPut(vc *Context) {
|
func PoolPut(vc *Context) {
|
||||||
if vc == nil {
|
if vc == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 清理引用
|
ReleaseContext(vc)
|
||||||
vc.ctx = nil
|
|
||||||
vc.status = 0
|
|
||||||
vc.bodySize = 0
|
|
||||||
vc.duration = 0
|
|
||||||
vc.serverName = ""
|
|
||||||
|
|
||||||
pool.Put(vc)
|
|
||||||
|
|
||||||
// 更新统计
|
// 更新统计
|
||||||
statsMu.Lock()
|
statsMu.Lock()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user