1 Star 0 Fork 0

余济舟/util

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
http_client_multiple.go 1.02 KB
一键复制 编辑 原始数据 按行查看 历史
余济舟 提交于 2024-08-09 16:32 . [optimize] 增加http-client
package httpClient
import (
"sync"
)
type HttpClientMultiple struct {
clients []*HttpClient
}
// New New 实例化:批量请求对象
func (HttpClientMultiple) New() *HttpClientMultiple {
return &HttpClientMultiple{}
}
// Add 添加httpClient对象
func (receiver *HttpClientMultiple) Add(hc *HttpClient) *HttpClientMultiple {
receiver.clients = append(receiver.clients, hc)
return receiver
}
// SetClients 设置httpClient对象
func (receiver *HttpClientMultiple) SetClients(clients []*HttpClient) *HttpClientMultiple {
receiver.clients = clients
return receiver
}
// Send 批量发送
func (receiver *HttpClientMultiple) Send() *HttpClientMultiple {
if len(receiver.clients) > 0 {
var wg sync.WaitGroup
wg.Add(len(receiver.clients))
for _, client := range receiver.clients {
go func(client *HttpClient) {
defer wg.Done()
client.Send()
}(client)
}
wg.Wait()
}
return receiver
}
// GetClients 获取链接池
func (receiver *HttpClientMultiple) GetClients() []*HttpClient {
return receiver.clients
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/jericho-yu/util.git
git@gitee.com:jericho-yu/util.git
jericho-yu
util
util
v2.14.19

搜索帮助