代码拉取完成,页面将自动刷新
package pool
import (
"bytes"
"crypto/md5"
"net/http"
"sync"
"time"
)
var (
Md5ObjPool *sync.Pool
httpClientPool *sync.Pool
bytesBufferPool *sync.Pool
)
func init() {
Md5ObjPool = &sync.Pool{
New: func() interface{} {
return md5.New()
},
}
httpClientPool = &sync.Pool{
New: func() interface{} {
t := http.DefaultTransport.(*http.Transport).Clone()
t.MaxIdleConns = 100
t.MaxConnsPerHost = 100
t.MaxIdleConnsPerHost = 100
return &HttpClient{
Client: &http.Client{Timeout: time.Second * 10, Transport: t},
}
},
}
bytesBufferPool = &sync.Pool{
New: func() interface{} {
return &BytesBuff{
Buffer: bytes.NewBuffer(make([]byte, 0, 1024)),
}
},
}
}
type BytesBuff struct {
*bytes.Buffer
}
func (b *BytesBuff) Free() {
b.Reset()
bytesBufferPool.Put(b)
}
func NewMyBytesBuff() *BytesBuff {
return bytesBufferPool.Get().(*BytesBuff)
}
type HttpClient struct {
*http.Client
}
func (b *HttpClient) Free() {
httpClientPool.Put(b)
}
func NewHttpClient() *HttpClient {
return httpClientPool.Get().(*HttpClient)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。