package goproxy import "sync" // 泛型对象池 type pool[T any] struct { pool sync.Pool } func newPool[T any](newFunc func() T) *pool[T] { return &pool[T]{ pool: sync.Pool{ New: func() interface{} { return newFunc() }, }, } } func (p *pool[T]) Get() T { return p.pool.Get().(T) } func (p *pool[T]) Put(x T) { p.pool.Put(x) }