mirror of
https://github.com/datarhei/core.git
synced 2025-10-06 00:17:07 +08:00
Move content encoding in the beginning of the middleware chain, update dependencies
This commit is contained in:
33
mem/buffer.go
Normal file
33
mem/buffer.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package mem
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type BufferPool struct {
|
||||
pool sync.Pool
|
||||
}
|
||||
|
||||
func NewBufferPool() *BufferPool {
|
||||
p := &BufferPool{
|
||||
pool: sync.Pool{
|
||||
New: func() any {
|
||||
return &bytes.Buffer{}
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *BufferPool) Get() *bytes.Buffer {
|
||||
buf := p.pool.Get().(*bytes.Buffer)
|
||||
buf.Reset()
|
||||
|
||||
return buf
|
||||
}
|
||||
|
||||
func (p *BufferPool) Put(buf *bytes.Buffer) {
|
||||
p.pool.Put(buf)
|
||||
}
|
Reference in New Issue
Block a user