traefik/pkg/proxy/httputil/bufferpool.go

30 lines
403 B
Go
Raw Normal View History

package httputil
2018-06-07 07:46:03 +00:00
import "sync"
const bufferSize = 32 * 1024
type bufferPool struct {
pool sync.Pool
}
2018-06-07 07:46:03 +00:00
func newBufferPool() *bufferPool {
b := &bufferPool{
pool: sync.Pool{},
2018-06-07 07:46:03 +00:00
}
b.pool.New = func() interface{} {
return make([]byte, bufferSize)
}
return b
2018-06-07 07:46:03 +00:00
}
func (b *bufferPool) Get() []byte {
return b.pool.Get().([]byte)
}
func (b *bufferPool) Put(bytes []byte) {
b.pool.Put(bytes)
}