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.
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 ¶
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.
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.