Documentation
¶
Index ¶
Constants ¶
View Source
const ( // RotationKeyPrefix is the prefix for proxy rotation keys in Redis. RotationKeyPrefix = "proxy_rotation" // LastSuccessKeyPrefix is the prefix for storing last successful proxy index per endpoint. LastSuccessKeyPrefix = "proxy_last_success" // UnhealthyKeyPrefix is the prefix for storing unhealthy proxy status. UnhealthyKeyPrefix = "proxy_unhealthy" )
Variables ¶
View Source
var ( // NumericIDPattern matches any sequence of digits for path normalization. NumericIDPattern = regexp.MustCompile(`^\d+$`) // CDNHashPattern matches the hash portion of CDN URLs. CDNHashPattern = regexp.MustCompile(`30DAY-Avatar-[0-9A-F]{32}-Png`) )
Functions ¶
func GetNormalizedPath ¶
GetNormalizedPath returns a normalized path where numeric IDs and CDN hashes are replaced with placeholders.
Types ¶
type EndpointPattern ¶
type EndpointPattern struct {
// contains filtered or unexported fields
}
EndpointPattern is a regex pattern for an endpoint.
type Middleware ¶
type Middleware struct {
// contains filtered or unexported fields
}
Middleware manages proxy rotation and endpoint-specific rate limiting for HTTP requests.
func New ¶
func New(proxies []*url.URL, client rueidis.Client, cfg *config.CommonConfig, requestTimeout time.Duration) *Middleware
New creates a new Middleware instance.
func (*Middleware) Cleanup ¶
func (m *Middleware) Cleanup()
Cleanup closes idle connections in the transport pool.
func (*Middleware) GetProxies ¶
func (m *Middleware) GetProxies() []*url.URL
GetProxies returns the list of proxies.
func (*Middleware) Process ¶
func (m *Middleware) Process( ctx context.Context, httpClient *http.Client, req *http.Request, next middleware.NextFunc, ) (*http.Response, error)
Process applies proxy logic before passing the request to the next middleware.
func (*Middleware) SetLogger ¶
func (m *Middleware) SetLogger(l logger.Logger)
SetLogger sets the logger for the middleware.
Click to show internal directories.
Click to hide internal directories.