crawl

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package crawl runs the Douban mirror: it drains the frontier, fetches each URL through the source that serves it, stores the raw bytes and a record, expands the links it discovers, and marks every row's outcome. The engine is resumable (in-flight rows stay pending) and polite (per-host rate limiting), and it never silently caps; it logs what it blocks or skips.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Concurrency int           // worker pool size (default 4)
	Limit       int           // max URLs to process this run (0 = drain the frontier)
	HTMLDelay   time.Duration // per-host spacing for HTML hosts (default 5s)
	Types       []string      // restrict to these entity types (empty = all)
	Source      string        // restrict to this source (empty = all)
	Logf        func(format string, args ...any)
}

Config tunes a crawl run.

type Engine

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

Engine ties the store and fetchers together.

func New

func New(st *store.Store, html HTMLClient, frodo FrodoClient, cfg Config) *Engine

New builds an Engine. Either fetcher may be nil if a run touches only the other source.

func (*Engine) Run

func (e *Engine) Run(ctx context.Context) (Stats, error)

Run drains pending frontier rows (subject to the configured filters and limit) until none remain or the context is cancelled. Newly discovered links are enqueued as it goes, so a single Run expands the mirror outward from its seeds.

type FrodoClient

type FrodoClient interface {
	Get(ctx context.Context, path string, params url.Values) ([]byte, error)
}

FrodoClient fetches a signed API path. *douban.FrodoClient satisfies it.

type HTMLClient

type HTMLClient interface {
	Get(ctx context.Context, url string) ([]byte, error)
}

HTMLClient fetches an absolute URL. *douban.Client satisfies it.

type Stats

type Stats struct {
	Processed  int
	Done       int
	Failed     int
	Blocked    int
	Skipped    int
	Discovered int
}

Stats summarizes a run.

Jump to

Keyboard shortcuts

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