1 Star 0 Fork 0

FlyingOnion / httpclient

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
pool.go 641 Bytes
一键复制 编辑 原始数据 按行查看 历史
FlyingOnion 提交于 2022-03-11 16:11 . add files
package pool
import (
"net/http"
"sync"
)
var (
defaultPool = &Pool{}
globalPool = defaultPool
)
func Global() *Pool { return globalPool }
func SetGlobal(p *Pool) { globalPool = p }
func New() *Pool { return &Pool{} }
type Pool struct {
pool sync.Pool
}
func (p *Pool) Get() *http.Client {
if c, ok := p.pool.New().(*http.Client); ok {
return c
}
return &http.Client{}
}
func (p *Pool) GetWithTransport(tr http.RoundTripper) *http.Client {
c := p.Get()
c.Transport = tr
return c
}
func (p *Pool) Recycle(c *http.Client) {
c.Transport = nil
c.CheckRedirect = nil
c.Jar = nil
c.Timeout = 0
p.pool.Put(c)
}
Go
1
https://gitee.com/FlyingOnion/httpclient.git
git@gitee.com:FlyingOnion/httpclient.git
FlyingOnion
httpclient
httpclient
v0.1.2

搜索帮助