feat(websearch): proxy failover, timeout, quota-weighted load balancing
- Use proxyutil.ConfigureTransportProxy for unified proxy protocol support (HTTP/HTTPS/SOCKS5/SOCKS5H), replacing ad-hoc HTTP-only proxy code - Proxy errors return ErrProxyUnavailable → gateway triggers account switch via UpstreamFailoverError instead of fallback to direct connection - Timeout: proxy dial 3s, TLS handshake 3s, data transfer 60s - Mark proxy unavailable for 5 minutes in Redis on connectivity failure - Quota-weighted load balancing: providers with quota_limit>0 are selected by remaining quota (weighted random); quota_limit=0 providers treated as 0% weight and placed last
This commit is contained in:
@@ -3,6 +3,7 @@ package service
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
@@ -147,6 +148,13 @@ func (s *GatewayService) handleWebSearchEmulation(
|
||||
|
||||
resp, providerName, err := doWebSearch(ctx, account, query)
|
||||
if err != nil {
|
||||
// Proxy unavailable → trigger account switch via UpstreamFailoverError
|
||||
if errors.Is(err, websearch.ErrProxyUnavailable) {
|
||||
return nil, &UpstreamFailoverError{
|
||||
StatusCode: http.StatusBadGateway,
|
||||
ResponseBody: []byte(err.Error()),
|
||||
}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user