62 lines
1.6 KiB
Go
62 lines
1.6 KiB
Go
package provider
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
proxyDomain "github.com/proxy-pool/proxy-pool/internal/domain/proxy"
|
|
"github.com/proxy-pool/proxy-pool/internal/domain/upstream"
|
|
)
|
|
|
|
type FetchResponse struct {
|
|
// Body belongs to the caller until Parse returns and must not be reused earlier.
|
|
Body []byte
|
|
RetryAfter time.Duration
|
|
}
|
|
|
|
// ProviderAdapter may be called concurrently up to Config.MaxInFlight times.
|
|
type ProviderAdapter interface {
|
|
Fetch(context.Context) (FetchResponse, error)
|
|
}
|
|
|
|
// RetryableError lets an adapter stop retries for permanent provider failures.
|
|
// Plain errors are treated as transient for backward-compatible fail-safe retries.
|
|
type RetryableError interface {
|
|
error
|
|
Retryable() bool
|
|
}
|
|
|
|
// Parser must be safe for concurrent calls and must honor context cancellation.
|
|
type Parser interface {
|
|
Parse(context.Context, []byte) ([]proxyDomain.Proxy, error)
|
|
}
|
|
|
|
// CandidateSink owns deduplication, is concurrency-safe, and returns the new
|
|
// count. On error it must not retain candidates; a successful count must be
|
|
// between zero and len(candidates).
|
|
type CandidateSink interface {
|
|
Add(context.Context, string, []proxyDomain.Proxy) (int, error)
|
|
}
|
|
|
|
type Result struct {
|
|
UpstreamID string
|
|
Class upstream.FetchClass
|
|
ValidCount int
|
|
NewCount int
|
|
Err error
|
|
Attempt int
|
|
}
|
|
|
|
type ResultRecorder interface {
|
|
// Record may be called concurrently and must not retain mutable result data.
|
|
Record(Result)
|
|
}
|
|
|
|
type Ports struct {
|
|
Adapter ProviderAdapter
|
|
Parser Parser
|
|
Candidates CandidateSink
|
|
Results ResultRecorder
|
|
Capacity upstream.FetchCapacity
|
|
}
|