MCPcopy
hub / github.com/fish2018/pansou / doRequestWithRetry

Method doRequestWithRetry

plugin/erxiao/erxiao.go:481–504  ·  view source on GitHub ↗

doRequestWithRetry 带重试的HTTP请求

(req *http.Request, client *http.Client)

Source from the content-addressed store, hash-verified

479
480// doRequestWithRetry 带重试的HTTP请求
481func (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 获取性能统计信息
507func (p *ErxiaoAsyncPlugin) GetPerformanceStats() map[string]interface{} {

Callers 2

searchImplMethod · 0.95

Calls 2

NameMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected