redirectcheck

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package redirectcheck verifies a redirect-rule CSV export (HubSpot's URL Redirects tool schema) against a live site: whether each rule's source still redirects correctly, whether its target is a live page, and whether both sides agree with the site's current sitemap.xml.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DiscoverSitemap

func DiscoverSitemap(ctx context.Context, fetcher crawler.Fetcher, domain, override string) (map[string]bool, error)

DiscoverSitemap fetches and parses the sitemap for domain, returning the normalized set of <loc> URLs it declares. If override is non-empty it is used as the only candidate; otherwise the conventional /sitemap.xml and /sitemap_index.xml locations are tried. An error is returned if nothing usable is found at any candidate — callers should treat this as fatal, since sitemap-membership columns would otherwise be silently wrong for every row.

func WriteCSV

func WriteCSV(w io.Writer, rules []Rule, results []RowResult) error

WriteCSV writes rules and their check results as a CSV: the original columns verbatim, plus the appended verdict columns. Every input row is present in the output, in order.

Types

type RowResult

type RowResult struct {
	Scope               Scope
	SourceStatus        int
	SourceFinalURL      string
	SourceMatchesTarget bool
	TargetStatus        int
	OriginalInSitemap   bool
	TargetInSitemap     bool
	Verdict             Verdict
	Notes               []string
}

RowResult is what checking one rule against the live site produced.

func CheckRule

func CheckRule(ctx context.Context, fetcher crawler.Fetcher, domain string, rule Rule, sitemapURLs map[string]bool) RowResult

CheckRule fetches rule's Original and Target URLs against the live site and returns the resulting verdict. sitemapURLs is the set discovered by DiscoverSitemap. Callers should only call this for rules classified ScopeInScope.

func Run

func Run(ctx context.Context, rules []Rule, opts RunOptions) ([]RowResult, error)

Run classifies every rule, fetches the site's sitemap once, then checks each in-scope rule concurrently (bounded by opts.Concurrency and opts.RatePerSecond). Every fetch — sitemap discovery included — goes through a shared AdaptiveLimiter, so a run that starts too aggressively for the target site backs itself off instead of hammering it into a bot-mitigation block. Results are returned in the same order as rules. Rows classified external or dynamic-pattern are not fetched.

type Rule

type Rule struct {
	Original            string
	Target              string
	RedirectType        string
	RedirectStyle       string
	Priority            string
	MatchQueryStrings   string
	IgnoreTrailingSlash string
	IgnoreProtocol      string
	DisableIfPageExists string
	Note                string
}

Rule is one row of the redirect-rule CSV. Columns are kept as raw strings so they can be echoed back verbatim in the output report.

func ParseCSV

func ParseCSV(r io.Reader) ([]Rule, error)

ParseCSV reads a HubSpot-format redirect-rule export. It returns an error if the header doesn't match the expected column schema.

type RunOptions

type RunOptions struct {
	Domain        string
	SitemapURL    string
	Fetcher       crawler.Fetcher
	Concurrency   int
	RatePerSecond float64
	// AdaptiveDelay automatically slows requests (halving requests-per-second, honoring any
	// Retry-After header) when the site responds with HTTP 429/503, the same way the crawl
	// engine does. Without it, a fixed concurrency/rate that's too aggressive for the target
	// can trip bot-mitigation (e.g. Cloudflare) partway through a run.
	AdaptiveDelay bool
	// Stats, if non-nil, is filled in with adaptive-delay activity once Run returns.
	Stats *RunStats
}

RunOptions configures a check-redirects run.

type RunStats

type RunStats struct {
	ThrottleEvents int
	FinalRate      float64
}

RunStats reports adaptive-delay activity for a Run call.

type Scope

type Scope string

Scope classifies a rule by where its target points, relative to the configured main domain.

const (
	ScopeInScope  Scope = "in-scope"
	ScopeExternal Scope = "external"
	ScopeDynamic  Scope = "dynamic-pattern"
)

func Classify

func Classify(rule Rule, domain string) (Scope, error)

Classify determines a rule's Scope. An error is returned only if the target can't be parsed as a URL at all.

type Verdict

type Verdict string

Verdict is the overall pass/fail assessment of one row.

const (
	VerdictOK              Verdict = "ok"
	VerdictWarning         Verdict = "warning"
	VerdictError           Verdict = "error"
	VerdictSkippedExternal Verdict = "skipped-external"
	VerdictSkippedDynamic  Verdict = "skipped-dynamic"
)

Jump to

Keyboard shortcuts

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