config

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package config defines gocrawl's layered configuration (defaults -> YAML file -> env -> flags) and maps it onto crawler.Options.

Index

Constants

View Source
const ExampleYAML = `` /* 5240-byte string literal not displayed */

ExampleYAML is a fully-commented starter configuration written by `gocrawl init`. It is the single source of truth for that template: configs/example.yaml and the "Example config file" block in docs/configuration.md are copies, and TestExampleYAMLCopiesAreInSync fails if either drifts from this constant.

Variables

This section is empty.

Functions

func WriteExample

func WriteExample(path string) error

WriteExample writes the example configuration to path, refusing to overwrite an existing file.

Types

type AnalyzersConfig

type AnalyzersConfig struct {
	Enabled  []string `mapstructure:"enabled"`
	Disabled []string `mapstructure:"disabled"`
	// Specialized turns on opt-in checks that are off by default: the lower-confidence
	// AI-search heuristics (AEO direct-answer-lead, GEO quotable-density) and the WordPress
	// analyzer's active security-endpoint probes. They only fire when this is set.
	Specialized bool `mapstructure:"specialized"`
	// SecurityAudit turns on the `security` analyzer's opt-in audit pass: TLS protocol and
	// certificate inspection, Set-Cookie attribute hygiene, and the deeper response-header
	// policy checks. It is passive — it reads the crawl's own responses and opens no extra
	// connections — but its findings are infrastructure rather than SEO, so it stays off
	// unless asked for.
	SecurityAudit bool `mapstructure:"security_audit"`
}

AnalyzersConfig selects which analyzers run.

type Config

type Config struct {
	Seed      string          `mapstructure:"seed"`
	Render    string          `mapstructure:"render"`
	Crawl     CrawlConfig     `mapstructure:"crawl"`
	Output    OutputConfig    `mapstructure:"output"`
	Analyzers AnalyzersConfig `mapstructure:"analyzers"`
	Store     StoreConfig     `mapstructure:"store"`
}

Config is the full gocrawl configuration.

func Default

func Default() Config

Default returns the built-in default configuration.

func Load

func Load(path string) (Config, error)

Load reads configuration from the optional YAML file at path (empty = none), overlaid on defaults, then GOCRAWL_* environment variables.

func (Config) ToOptions

func (c Config) ToOptions() (crawler.Options, error)

ToOptions compiles the crawl config into crawler.Options, compiling include/exclude regexes.

func (Config) Validate

func (c Config) Validate() error

Validate checks for obviously invalid settings.

type CrawlConfig

type CrawlConfig struct {
	MaxDepth      int     `mapstructure:"max_depth"`
	MaxPages      int     `mapstructure:"max_pages"`
	Concurrency   int     `mapstructure:"concurrency"`
	RatePerSecond float64 `mapstructure:"rate_per_second"`
	UserAgent     string  `mapstructure:"user_agent"`
	// UserAgents is an optional pool of User-Agent strings rotated across requests; it
	// supersedes UserAgent when set. UserAgentRotation is off, round-robin, or random.
	UserAgents        []string `mapstructure:"user_agents"`
	UserAgentRotation string   `mapstructure:"user_agent_rotation"`
	// Proxy is a single proxy URL; Proxies is a pool to rotate across (Proxy, if set, is
	// prepended to the pool). ProxyRotation is off, round-robin, random, or sticky-host.
	Proxy         string   `mapstructure:"proxy"`
	Proxies       []string `mapstructure:"proxies"`
	ProxyRotation string   `mapstructure:"proxy_rotation"`
	// BasicAuth is "user:pass" sent as an HTTP Basic Authorization header on every request to
	// the crawled host — for sites gated by server-level Basic Auth, which is common on
	// staging/acceptance environments (e.g. a reverse-proxy realm challenge in front of the
	// whole site, independent of any app-level login).
	BasicAuth string        `mapstructure:"basic_auth"`
	Timeout   time.Duration `mapstructure:"timeout"`
	// MaxDuration bounds the crawl's total wall-clock time (0 = unlimited). When it elapses,
	// the crawl stops early and still produces a report from whatever was fetched so far.
	MaxDuration     time.Duration `mapstructure:"max_duration"`
	MaxBodyBytes    int64         `mapstructure:"max_body_bytes"`
	RespectRobots   bool          `mapstructure:"respect_robots"`
	AllowSubdomains bool          `mapstructure:"allow_subdomains"`
	FollowExternal  bool          `mapstructure:"follow_external"`
	FollowNofollow  bool          `mapstructure:"follow_nofollow"`
	StripQuery      bool          `mapstructure:"strip_query"`
	Verbose         bool          `mapstructure:"verbose"`
	AdaptiveDelay   bool          `mapstructure:"adaptive_delay"`
	Include         []string      `mapstructure:"include"`
	Exclude         []string      `mapstructure:"exclude"`
}

CrawlConfig controls crawl scope and politeness.

type OutputConfig

type OutputConfig struct {
	Format string `mapstructure:"format"`
	Path   string `mapstructure:"path"`
	// SitemapPath, when set, writes a standard sitemap.xml of the crawled pages to that path as
	// a side output (independent of Format). The crawled site is also always rendered as a "Site
	// map" tab in the HTML report.
	SitemapPath string `mapstructure:"sitemap_path"`
}

OutputConfig controls report output.

type StoreConfig added in v0.3.0

type StoreConfig struct {
	// Dir is the store root; empty means store.DefaultRoot() (~/.gocrawl/crawls).
	Dir string `mapstructure:"dir"`
}

StoreConfig controls the on-disk crawl store used by `--save`, `gocrawl history`, and `gocrawl compare`.

Jump to

Keyboard shortcuts

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