Documentation
¶
Overview ¶
Package config defines gocrawl's layered configuration (defaults -> YAML file -> env -> flags) and maps it onto crawler.Options.
Index ¶
- Constants
- Variables
- func DeleteHeaderProfile(name string) error
- func HeaderProfileDir() string
- func HeaderProfilePath(name string) (string, error)
- func ListHeaderProfiles() ([]string, error)
- func ReadHeaderProfile(name string) (string, error)
- func SaveHeaderProfile(name, body string) error
- func WriteExample(path string) error
- type AnalyzersConfig
- type Config
- type CrawlConfig
- type OutputConfig
- type StoreConfig
Constants ¶
const ExampleYAML = `` /* 6829-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 ¶
var ErrInvalidHeaderProfile = errors.New("invalid header profile")
ErrInvalidHeaderProfile marks a header profile name or body that can't be used. The web API maps it to 400; a profile that doesn't exist wraps fs.ErrNotExist instead.
Functions ¶
func DeleteHeaderProfile ¶
DeleteHeaderProfile removes a profile's file.
func HeaderProfileDir ¶ added in v0.9.0
func HeaderProfileDir() string
HeaderProfileDir is where named header profiles live: ~/.gocrawl/headers, alongside the crawl store's ~/.gocrawl/crawls.
func HeaderProfilePath ¶ added in v0.9.0
HeaderProfilePath resolves a header profile name to <HeaderProfileDir>/<name>.headers.
func ListHeaderProfiles ¶
ListHeaderProfiles returns the names of the profiles in HeaderProfileDir, sorted. A missing directory is not an error: no profile has been saved yet.
func ReadHeaderProfile ¶
ReadHeaderProfile returns a profile's file content.
func SaveHeaderProfile ¶
SaveHeaderProfile validates body with crawler.ParseHeaderLines and writes it atomically to the profile's file with mode 0600, in a 0700 directory: profiles hold access secrets. Windows line endings are normalized and a final newline is added. A rejected body is reported by line number only; its content never appears in the error.
func WriteExample ¶
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"`
// IgnoreExternalTagging suppresses the utm analyzer's per-link tagging-quality warnings
// (partial/empty/duplicate/casing) for links leaving the crawled domain, since the site
// owner doesn't control tagging on links it doesn't own. On by default; the utm-summary
// rollup and utm-internal-tagged are unaffected.
IgnoreExternalTagging bool `mapstructure:"ignore_external_tagging"`
}
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 Load ¶
Load reads configuration from the optional YAML file at path (empty = none), overlaid on defaults, then GOCRAWL_* environment variables.
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"`
// Cookie is sent verbatim as the Cookie header on every request to the crawled host — for
// app-level session gates (e.g. a Shopify storefront password page) where the operator
// already has a valid session and supplies its cookie by hand, as opposed to BasicAuth's
// server-level realm challenge.
Cookie string `mapstructure:"cookie"`
// Headers are extra request headers as "Name: value" strings, sent on every request to
// the crawled host and scoped like BasicAuth and Cookie. HeaderFile names a file of such
// lines, and HeaderProfile names one stored in HeaderProfileDir() — the form the MCP and
// web APIs accept, so a caller can pick a header set without seeing (or being able to
// point gocrawl at) arbitrary files. All three may be combined; for a name set more than
// once, Headers beats HeaderFile, which beats HeaderProfile.
Headers []string `mapstructure:"headers"`
HeaderFile string `mapstructure:"header_file"`
HeaderProfile string `mapstructure:"header_profile"`
// BearerToken is sent as "Authorization: Bearer <token>" through the custom-headers path,
// so it gets exactly the host restriction Headers get. It can't be combined with
// BasicAuth or a custom Authorization header, which set the same header.
BearerToken string `mapstructure:"bearer_token"`
Timeout time.Duration `mapstructure:"timeout"`
// MaxDuration bounds the crawl's active time, excluding time spent paused (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`.