From 4a93cf2b5c0f126947b304af6bdce268b8876ba1 Mon Sep 17 00:00:00 2001 From: xfy Date: Fri, 10 Apr 2026 11:20:50 +0800 Subject: [PATCH] =?UTF-8?q?refactor(variable):=20=E7=AE=80=E5=8C=96?= =?UTF-8?q?=E5=8F=98=E9=87=8F=E6=B1=A0=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - PoolGet() 改为调用 NewContext() - PoolPut() 改为调用 ReleaseContext() - 添加 Deprecated 文档注释 Co-Authored-By: Claude Opus 4.6 --- internal/variable/pool.go | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/internal/variable/pool.go b/internal/variable/pool.go index 1d3358f..3c74fa4 100644 --- a/internal/variable/pool.go +++ b/internal/variable/pool.go @@ -40,23 +40,10 @@ func GetPool() *sync.Pool { } // PoolGet 从池中获取 Context(包装方法,用于统计) +// +// Deprecated: 使用 NewContext 代替,该函数保持向后兼容。 func PoolGet(ctx *fasthttp.RequestCtx) *Context { - vc := pool.Get().(*Context) - - // 初始化 - 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) - } + vc := NewContext(ctx) // 更新统计 statsMu.Lock() @@ -68,19 +55,14 @@ func PoolGet(ctx *fasthttp.RequestCtx) *Context { } // PoolPut 将 Context 放回池中(包装方法,用于统计) +// +// Deprecated: 使用 ReleaseContext 代替,该函数保持向后兼容。 func PoolPut(vc *Context) { if vc == nil { return } - // 清理引用 - vc.ctx = nil - vc.status = 0 - vc.bodySize = 0 - vc.duration = 0 - vc.serverName = "" - - pool.Put(vc) + ReleaseContext(vc) // 更新统计 statsMu.Lock()