Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Fetcher ¶
type Fetcher interface {
// FetchURLAsString fetches the content of a URL as a string.
FetchURLAsString(ctx context.Context, url string) (string, error)
// FetchURL fetches the content of a URL as a byte slice.
FetchURL(ctx context.Context, url string) ([]byte, error)
// StreamURL streams the content of a URL to the provided writer.
StreamURL(ctx context.Context, url string, writer io.Writer) error
}
func FromConfig ¶
func FromConfig(cfg FetcherConfig) Fetcher
type FetcherConfig ¶
type HTTPClient ¶
HTTPClient is an interface for HTTP clients.
type HTTPFetcher ¶
type HTTPFetcher struct {
// contains filtered or unexported fields
}
HTTPFetcher provides utilities for fetching content via HTTP.
func NewHTTPFetcher ¶
func NewHTTPFetcher(opts ...HTTPFetcherOption) *HTTPFetcher
NewHTTPFetcher creates a new HTTP fetcher with the given options.
func (*HTTPFetcher) FetchURLAsString ¶
FetchURLAsString retrieves content from a URL as a string.
type HTTPFetcherOption ¶
type HTTPFetcherOption func(*HTTPFetcher)
HTTPFetcherOption configures an HTTPFetcher.
func WithClient ¶
func WithClient(client HTTPClient) HTTPFetcherOption
WithClient sets a custom HTTP client.
func WithTimeout ¶
func WithTimeout(timeout time.Duration) HTTPFetcherOption
WithTimeout sets the timeout for HTTP requests.
func WithUserAgent ¶
func WithUserAgent(userAgent string) HTTPFetcherOption
WithUserAgent sets the User-Agent header for requests.
type LimitedFetcher ¶
type LimitedFetcher struct {
Fetcher *HTTPFetcher
// contains filtered or unexported fields
}
LimitedFetcher wraps an HTTP fetcher with rate limiting.
func NewLimitedFetcher ¶
func NewLimitedFetcher(fetcher *HTTPFetcher, minInterval time.Duration) *LimitedFetcher
NewLimitedFetcher creates a new rate-limited HTTP fetcher.
func (*LimitedFetcher) FetchURLAsString ¶
FetchURLAsString fetches a URL as a string with rate limiting.
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter limits the rate of requests to a domain.
func NewRateLimiter ¶
func NewRateLimiter(minInterval time.Duration) *RateLimiter
NewRateLimiter creates a new rate limiter with the given minimum interval between requests.