doRequestWithRetry 带重试的HTTP请求
(req *http.Request, client *http.Client)
| 479 | |
| 480 | // doRequestWithRetry 带重试的HTTP请求 |
| 481 | func (p *ErxiaoAsyncPlugin) doRequestWithRetry(req *http.Request, client *http.Client) (*http.Response, error) { |
| 482 | maxRetries := 2 |
| 483 | var lastErr error |
| 484 | |
| 485 | for i := 0; i < maxRetries; i++ { |
| 486 | resp, err := client.Do(req) |
| 487 | if err == nil { |
| 488 | if resp.StatusCode == http.StatusOK { |
| 489 | return resp, nil |
| 490 | } |
| 491 | resp.Body.Close() |
| 492 | lastErr = fmt.Errorf("HTTP状态码: %d", resp.StatusCode) |
| 493 | } else { |
| 494 | lastErr = err |
| 495 | } |
| 496 | |
| 497 | // 快速重试:只等待很短时间 |
| 498 | if i < maxRetries-1 { |
| 499 | time.Sleep(100 * time.Millisecond) |
| 500 | } |
| 501 | } |
| 502 | |
| 503 | return nil, fmt.Errorf("[%s] 请求失败,重试%d次后仍失败: %w", p.Name(), maxRetries, lastErr) |
| 504 | } |
| 505 | |
| 506 | // GetPerformanceStats 获取性能统计信息 |
| 507 | func (p *ErxiaoAsyncPlugin) GetPerformanceStats() map[string]interface{} { |
no test coverage detected