Compare commits

2 Commits
Author SHA1 Message Date
ygxbnet 15c26f1939 refactor(uploader): 优化文件上传并发处理逻辑
构建上传工具 / build (push) Successful in 1m10s
- 将循环方式从索引遍历改为range方式
- 添加处理进程创建注释说明
- 在进度更新后添加延时避免过度频繁更新
- 修复空行处理时计数器递增逻辑
- 优化panic恢复处理流程
2026-07-28 09:21:13 +08:00
ygxbnet 1a95653894 config: 更新默认服务器地址配置
- 注释掉本地回环地址配置
- 修改默认URL为生产环境地址 http://112.124.71.39:8080
- 保留其他配置项不变
2026-07-28 09:21:12 +08:00
2 changed files with 7 additions and 2 deletions
+2 -1
View File
@@ -34,7 +34,8 @@ const (
func InitConfig() { func InitConfig() {
// 设置默认配置 // 设置默认配置
defaultConfig := Config{ defaultConfig := Config{
Url: "http://127.0.0.1:8080", //Url: "http://127.0.0.1:8080",
Url: "http://112.124.71.39:8080",
Token: "", Token: "",
ThreadCount: 10, ThreadCount: 10,
HandleFileCount: 25, HandleFileCount: 25,
+5 -1
View File
@@ -334,7 +334,7 @@ func processFile(ctx context.Context, logChan *chan string, filePath string, fil
lines := make(chan string, 200) lines := make(chan string, 200)
var countLine int32 = 0 var countLine int32 = 0
// 创建指定个worker同时处理文件上传 // 创建指定个worker同时处理文件上传
for i := 0; i < config.APPConfig.ThreadCount; i++ { for i := range config.APPConfig.ThreadCount {
select { select {
case <-ctx.Done(): case <-ctx.Done():
close(lines) close(lines)
@@ -342,6 +342,7 @@ func processFile(ctx context.Context, logChan *chan string, filePath string, fil
default: default:
} }
//创建处理进程
go func() { go func() {
processLines(ctx, logChan, &lines, i, filePath, &countLine) processLines(ctx, logChan, &lines, i, filePath, &countLine)
}() }()
@@ -356,6 +357,7 @@ func processFile(ctx context.Context, logChan *chan string, filePath string, fil
fmt.Println("panic:", f+":"+strconv.Itoa(l), r) fmt.Println("panic:", f+":"+strconv.Itoa(l), r)
} }
}() }()
for scanner.Scan() { for scanner.Scan() {
select { select {
case <-ctx.Done(): case <-ctx.Done():
@@ -384,6 +386,7 @@ func processFile(ctx context.Context, logChan *chan string, filePath string, fil
Percentage: int(float64(countLine) / float64(fileLines) * 100), Percentage: int(float64(countLine) / float64(fileLines) * 100),
}, },
) )
time.Sleep(50 * time.Millisecond)
} }
//上传完成,进度设为100 //上传完成,进度设为100
progress.Store(filepath.Base(filePath), progress.Store(filepath.Base(filePath),
@@ -415,6 +418,7 @@ func processLines(ctx context.Context, logChan *chan string, lines *chan string,
// 跳过空行 // 跳过空行
if strings.TrimSpace(line) == "" { if strings.TrimSpace(line) == "" {
atomic.AddInt32(countLine, 1)
continue continue
} }
// 上传数据 // 上传数据