refactor(uploader): 优化文件上传并发处理逻辑
构建上传工具 / build-tool (push) Successful in 1m46s

- 将初始化连接池的并发方式改为waitgroup控制的goroutine池
- 调整文件处理时的channel缓冲区大小从100增加到200
- 移除不必要的sync.WaitGroup变量声明
- 修改进度计算逻辑,确保上传完成时进度显示为100%
- 添加对processLines函数的功能注释
- 优化上下文取消时的资源清理流程,及时关闭channel
This commit is contained in:
2026-04-28 15:43:02 +08:00
parent 1cac9e9013
commit 73a7d26816
2 changed files with 42 additions and 23 deletions
+19 -10
View File
@@ -7,6 +7,7 @@ import (
"io"
"net/http"
"net/url"
"sync"
"time"
)
@@ -28,17 +29,25 @@ func init() {
// InitConn 创建连接池
func InitConn() {
for i := 0; i < 200; i++ {
resp, err := httpClient.Get(config.APPConfig.Url + "/api/test")
if err != nil {
fmt.Println(err)
return
}
defer func() {
io.Copy(io.Discard, resp.Body)
resp.Body.Close()
}()
wg := &sync.WaitGroup{}
for i := 0; i < 10; i++ {
wg.Go(func() {
for i := 0; i < 50; i++ {
resp, err := httpClient.Get(config.APPConfig.Url + "/api/test")
if err != nil {
fmt.Println(err)
return
}
defer func() {
io.Copy(io.Discard, resp.Body)
resp.Body.Close()
}()
}
})
}
wg.Wait()
}
func UploadDataToServer(ctx context.Context, data string) error {