diff --git a/internal/variable/pool.go b/internal/variable/pool.go index deac4bb..0afe6c8 100644 --- a/internal/variable/pool.go +++ b/internal/variable/pool.go @@ -8,8 +8,6 @@ package variable import ( "sync" "sync/atomic" - - "github.com/valyala/fasthttp" ) // PoolStats 池统计信息。 @@ -54,34 +52,6 @@ func GetPool() *sync.Pool { return &pool } -// PoolGet 从池中获取 Context(包装方法,用于统计) -// -// Deprecated: 使用 NewContext 代替,该函数保持向后兼容。 -func PoolGet(ctx *fasthttp.RequestCtx) *Context { - vc := NewContext(ctx) - - // 更新统计 - gets.Add(1) - active.Store(gets.Load() - puts.Load()) - - return vc -} - -// PoolPut 将 Context 放回池中(包装方法,用于统计) -// -// Deprecated: 使用 ReleaseContext 代替,该函数保持向后兼容。 -func PoolPut(vc *Context) { - if vc == nil { - return - } - - ReleaseContext(vc) - - // 更新统计 - puts.Add(1) - active.Store(gets.Load() - puts.Load()) -} - // ResetStats 重置统计信息。 // // 将所有统计计数器清零,线程安全。 diff --git a/internal/variable/variable.go b/internal/variable/variable.go index 42c9d12..5bb1807 100644 --- a/internal/variable/variable.go +++ b/internal/variable/variable.go @@ -140,11 +140,6 @@ func NewContext(ctx *fasthttp.RequestCtx) *Context { return vc } -// NewVariableContext 是 NewContext 的别名(向后兼容) -func NewVariableContext(ctx *fasthttp.RequestCtx) *Context { - return NewContext(ctx) -} - // ReleaseContext 释放 Context 回池中 func ReleaseContext(vc *Context) { if vc == nil { @@ -163,11 +158,6 @@ func ReleaseContext(vc *Context) { pool.Put(vc) } -// ReleaseVariableContext 是 ReleaseContext 的别名(向后兼容) -func ReleaseVariableContext(vc *Context) { - ReleaseContext(vc) -} - // SetResponseInfo 设置响应信息(用于需要 status、body_bytes_sent、request_time 的场景) func (vc *Context) SetResponseInfo(status int, bodySize int64, durationNs int64) { vc.status = status diff --git a/internal/variable/variable_test.go b/internal/variable/variable_test.go index 9fb97c4..e320b3d 100644 --- a/internal/variable/variable_test.go +++ b/internal/variable/variable_test.go @@ -677,30 +677,30 @@ func TestExpandOnlyDollar(t *testing.T) { func TestPoolFunctions(t *testing.T) { ctx := mockRequestCtx(t) - // 测试 PoolGet 和 PoolPut - vc := PoolGet(ctx) + // 测试 NewContext 和 ReleaseContext + vc := NewContext(ctx) if vc == nil { - t.Fatal("PoolGet returned nil") + t.Fatal("NewContext returned nil") } // 设置一些值 vc.Set("test", "value") // 释放 - PoolPut(vc) + ReleaseContext(vc) // 再次获取应该被清空 - vc2 := PoolGet(ctx) + vc2 := NewContext(ctx) if _, ok := vc2.Get("test"); ok { - t.Error("expected context to be cleared after PoolPut") + t.Error("expected context to be cleared after ReleaseContext") } - PoolPut(vc2) + ReleaseContext(vc2) } -// TestPoolPutNil 测试 PoolPut nil +// TestPoolPutNil 测试 ReleaseContext nil func TestPoolPutNil(_ *testing.T) { // 不应该 panic - PoolPut(nil) + ReleaseContext(nil) } // TestStatsFunctions 测试统计相关函数