Skip to content

Commit 491d6d9

Browse files
author
wuwei
committed
2
1 parent 431f409 commit 491d6d9

3 files changed

Lines changed: 22 additions & 131 deletions

File tree

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ rss.opml
3232

3333
# 报告文件
3434
report-*.md
35+
*.md
3536

3637
#数据文件
3738
articles.db

‎.golangci.yml‎

Lines changed: 21 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,25 @@
44
run:
55
# 默认并发数为可用CPU数
66
concurrency: 4
7-
7+
88
# 超时设置,默认1分钟
99
timeout: 1m
10-
10+
1111
# 退出代码,如果至少有一个问题被发现
1212
issues-exit-code: 1
13-
13+
1414
# 包含测试文件
1515
tests: true
16-
17-
# 允许跳过目录
18-
skip-dirs:
19-
- vendor
20-
- data
21-
22-
# 允许跳过文件
23-
skip-files:
24-
- '.*_test\.go$'
2516

2617
# 输出配置选项
2718
output:
2819
# 输出格式: colored-line-number|line-number|json|tab|checkstyle|code-climate|junit-xml|github-actions
29-
format: colored-line-number
30-
20+
formats:
21+
- format: colored-line-number
22+
3123
# 打印行号
3224
print-issued-lines: true
33-
25+
3426
# 打印linter名称
3527
print-linter-name: true
3628

@@ -39,25 +31,17 @@ linters:
3931
# 启用所有linters
4032
enable-all: false
4133

42-
# 禁用特定linters
43-
disable:
44-
- exhaustivestruct # 已弃用
45-
- golint # 已弃用,使用revive代替
46-
- interfacer # 已弃用
47-
- maligned # 已弃用,使用govet代替
48-
- scopelint # 已弃用,使用exportloopref代替
49-
- varcheck # 已弃用,使用unused代替
50-
- deadcode # 已弃用,使用unused代替
51-
- structcheck # 已弃用,使用unused代替
34+
# 禁用特定linters (移除已废弃的检查器以避免警告)
35+
disable: []
5236

5337
# 启用特定linters
5438
enable:
5539
- asciicheck # 检查非ASCII标识符
5640
- bodyclose # 检查HTTP响应体是否关闭
41+
- copyloopvar # 检查循环变量引用 (替代exportloopref)
5742
- dogsled # 检查过多的空白标识符
5843
- dupl # 代码克隆检测器
5944
- errcheck # 检查未处理的错误
60-
- exportloopref # 检查循环变量引用
6145
- funlen # 检查函数长度
6246
- gochecknoinits # 检查init函数
6347
- goconst # 查找可以替换为常量的重复字符串
@@ -113,45 +97,21 @@ linters-settings:
11397
min-occurrences: 3
11498

11599
gocritic:
116-
# 启用特定检查器
100+
# 启用特定检查器 (只列出非默认启用的检查器)
117101
enabled-checks:
118102
- appendCombine
119-
- argOrder
120-
- assignOp
121-
- badCond
122103
- boolExprSimplify
123104
- builtinShadow
124-
- captLocal
125-
- caseOrder
126105
- commentedOutCode
127106
- commentedOutImport
128-
- defaultCaseOrder
129-
- dupBranchBody
130-
- dupCase
131-
- dupSubExpr
132-
- elseif
133107
- emptyFallthrough
134108
- equalFold
135-
- flagDeref
136-
- ifElseChain
137109
- importShadow
138110
- indexAlloc
139-
- mapKey
140-
- newDeref
141-
- offBy1
142111
- rangeExprCopy
143-
- regexpMust
144-
- sloppyLen
145112
- stringXbytes
146-
- switchTrue
147113
- typeAssertChain
148-
- typeSwitchVar
149-
- underef
150-
- unlambda
151114
- unnecessaryBlock
152-
- unslice
153-
- valSwap
154-
- wrapperFunc
155115

156116
misspell:
157117
# 美式英语
@@ -195,7 +155,16 @@ issues:
195155
max-issues-per-linter: 0
196156
# 每个文件修复相同问题的最大数量
197157
max-same-issues: 0
198-
158+
159+
# 排除特定目录
160+
exclude-dirs:
161+
- vendor
162+
- data
163+
164+
# 排除特定文件
165+
exclude-files:
166+
- '.*_test\.go$'
167+
199168
# 排除特定问题
200169
exclude-rules:
201170
# 排除测试文件中的一些问题

‎internal/application/service/rss_processor_service.go‎

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -585,85 +585,6 @@ func (s *rssProcessorService) processResponse(resp *http.Response, config model.
585585
return content, nil
586586
}
587587

588-
// 检查是否是可重试的错误
589-
if lastErr != nil && !s.isRetryableError(lastErr) {
590-
logger.Warn("遇到不可重试的错误,停止重试", "error", lastErr)
591-
break
592-
}
593-
594-
time.Sleep(backoffTime)
595-
}
596-
597-
start := time.Now()
598-
599-
// 为每次请求创建新的上下文,避免使用已取消的上下文
600-
ctx, cancel := context.WithTimeout(context.Background(), apiTimeout)
601-
602-
// 创建新的请求,使用新的上下文
603-
reqWithCtx := req.WithContext(ctx)
604-
resp, lastErr = client.Do(reqWithCtx)
605-
requestDuration = time.Since(start)
606-
607-
// 请求完成后取消上下文
608-
cancel()
609-
610-
// 处理错误情况
611-
if lastErr != nil {
612-
// 特别处理超时错误
613-
if strings.Contains(lastErr.Error(), "context deadline exceeded") || strings.Contains(lastErr.Error(), "timeout") {
614-
logger.Warn("API请求超时,准备重试", "error", lastErr, "attempt", retryCount+1, "duration_ms", requestDuration.Milliseconds())
615-
} else {
616-
logger.Warn("发送API请求失败,准备重试", "error", lastErr, "attempt", retryCount+1, "duration_ms", requestDuration.Milliseconds())
617-
}
618-
continue
619-
}
620-
621-
// 读取响应
622-
responseBody, err := s.readAPIResponse(resp, config)
623-
// 立即关闭响应体,避免在循环中使用defer
624-
if resp != nil && resp.Body != nil {
625-
if closeErr := resp.Body.Close(); closeErr != nil {
626-
logger.Warn("关闭响应体失败", "error", closeErr)
627-
}
628-
}
629-
630-
if err != nil {
631-
return "", err
632-
}
633-
634-
// 检查响应状态码并处理错误
635-
if resp.StatusCode != http.StatusOK {
636-
return "", s.handleAPIError(resp.StatusCode, responseBody, requestDuration)
637-
}
638-
639-
// 记录原始响应内容(仅记录预览,避免日志过大)
640-
responsePreview := string(responseBody)
641-
if len(responsePreview) > 200 {
642-
responsePreview = responsePreview[:200] + "..."
643-
}
644-
logger.Debug("Deepseek API原始响应", "response_length", len(responseBody), "response_preview", responsePreview)
645-
646-
// 处理响应
647-
content, err := s.processAPIResponse(responseBody, responsePreview)
648-
if err != nil {
649-
return "", err
650-
}
651-
652-
logger.Info("成功获取Deepseek API响应", "content_length", len(content), "duration_ms", requestDuration.Milliseconds())
653-
logger.Debug("API响应内容", "content", content)
654-
655-
return content, nil
656-
}
657-
658-
// 所有重试都失败
659-
if lastErr != nil {
660-
logger.Error("发送API请求失败,已达到最大重试次数", "error", lastErr, "max_retries", maxRetries)
661-
return "", fmt.Errorf("发送API请求失败: %w", lastErr)
662-
}
663-
664-
return "", nil
665-
}
666-
667588
// isRetryableError 判断错误是否可重试
668589
func (s *rssProcessorService) isRetryableError(err error) bool {
669590
if err == nil {

0 commit comments

Comments
 (0)