mirror of
				https://gitee.com/dromara/mayfly-go
				synced 2025-11-04 16:30:25 +08:00 
			
		
		
		
	
		
			
	
	
		
			30 lines
		
	
	
		
			449 B
		
	
	
	
		
			Go
		
	
	
	
	
	
		
		
			
		
	
	
			30 lines
		
	
	
		
			449 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| 
								 | 
							
								package esi
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								import (
							 | 
						||
| 
								 | 
							
									"net/http/httputil"
							 | 
						||
| 
								 | 
							
									"sync"
							 | 
						||
| 
								 | 
							
								)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								type BufferPool struct {
							 | 
						||
| 
								 | 
							
									pool *sync.Pool
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								// 需要实现 httputil.BufferPool
							 | 
						||
| 
								 | 
							
								var _ httputil.BufferPool = (*BufferPool)(nil)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								func NewBufferPool() *BufferPool {
							 | 
						||
| 
								 | 
							
									return &BufferPool{&sync.Pool{
							 | 
						||
| 
								 | 
							
										New: func() interface{} {
							 | 
						||
| 
								 | 
							
											return make([]byte, 32*1024)
							 | 
						||
| 
								 | 
							
										},
							 | 
						||
| 
								 | 
							
									}}
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								func (b *BufferPool) Get() []byte {
							 | 
						||
| 
								 | 
							
									return b.pool.Get().([]byte)
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								func (b *BufferPool) Put(buf []byte) {
							 | 
						||
| 
								 | 
							
									b.pool.Put(buf)
							 | 
						||
| 
								 | 
							
								}
							 |