fetch

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 24, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package fetch is the network engine: it turns a stream of seeds into a stream of results as fast as one machine sustains. It owns DNS, a sharded pool of keep-alive transports, per-host and per-IP concurrency limits, an adaptive timeout, and dead-host/dead-domain tracking so a run does not waste workers on targets that will never answer.

Index

Constants

This section is empty.

Variables

View Source
var ErrCongested = errors.New("gave up after congestion retries")

ErrCongested is recorded when a fetch still fails after exhausting its congestion retries. It is counted as a failure, not a skip, and it never trips the dead-domain breaker: the host may be fine, we simply could not get through within the retry budget.

Functions

func IsRetry

func IsRetry(err error) bool

IsRetry reports whether err is the sentinel retry error.

func IsSkip

func IsSkip(err error) bool

IsSkip reports whether err is the sentinel skip error.

Types

type Fetcher

type Fetcher struct {
	// contains filtered or unexported fields
}

Fetcher performs concurrent re-fetches with post-fetch digest comparison.

func New

func New(cfg config.Config) *Fetcher

New builds a Fetcher from config.

func (*Fetcher) Fetch

func (f *Fetcher) Fetch(ctx context.Context, s SeedURL) Result

Fetch performs one re-fetch and returns its Result, setting Unchanged when the fetched body's sha1 matches the seed's prior digest. It never returns an error itself; failures are reported in Result.Err.

func (*Fetcher) Limit

func (f *Fetcher) Limit() int

Limit reports the live in-flight concurrency limit, for progress display.

func (*Fetcher) Stop

func (f *Fetcher) Stop()

Stop releases the engine's blocking limiter so a cancelled run unwinds. It is safe to call once the run context is done.

type Result

type Result struct {
	URL       string
	FetchedAt time.Time

	// Set on a completed HTTP exchange.
	Status    int
	Header    http.Header
	ReqHeader http.Header
	Body      []byte
	Digest    string // sha1 hex of Body

	// ETag and LastModified are the response validators, carried into the
	// capture index so a later recrawl can issue a conditional request. On a
	// 304 they fall back to the validators the request sent.
	ETag         string
	LastModified string

	// Unchanged is true when Digest matches the seed's prior digest, so the
	// content did not change since it was last captured.
	Unchanged bool

	// Meta is carried verbatim from the seed.
	Meta map[string]string

	// Err is non-nil for transport/DNS/timeout failures (no HTTP response).
	Err error

	// Timing fields (zero if not captured).
	TTFB          time.Duration // time from request send to first byte of response
	FetchDuration time.Duration // total wall-clock from request start to body read done
	FinalURL      string        // URL after following redirects; equals URL if no redirect
	IP            string        // IP address of the server that responded
}

Result is the outcome of fetching one seed.

type SeedURL

type SeedURL struct {
	URL     string
	Digest  string
	ETag    string
	ModTime string
	Meta    map[string]string
}

SeedURL is the subset of a seed the fetcher needs, decoupling fetch from the seed package's concrete type.

Digest, ETag, and ModTime are validators from a prior capture of this URL. Digest drives post-fetch content comparison; ETag and ModTime drive conditional requests (If-None-Match / If-Modified-Since) so an unchanged page comes back as a bodiless 304.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL