robots

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package robots parses robots.txt per RFC 9309 and answers the one question the frontier asks: may meguri fetch this path?

The parser reduces a whole file to a single Rules value already specialized to meguri's user agent. It picks the most specific matching group, keeps that group's Allow and Disallow rules and Crawl-delay, and gathers the file-global Sitemap lines. Everything else is dropped.

The matcher follows the Google lineage that RFC 9309 standardized: longest pattern match wins, an Allow breaks a tie against an equally long Disallow, and only the two metacharacters * and $ are special.

Index

Constants

View Source
const MaxBytes = 500 << 10

MaxBytes is the RFC 9309 parse cap: a crawler must parse at least the first 500 KiB of a robots.txt and may stop after that. We stop exactly there so a hostile or runaway file cannot cost us more.

Variables

This section is empty.

Functions

This section is empty.

Types

type Rules

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

Rules is meguri's compact parsed form of one robots.txt, already reduced to the single group that applies to meguri's user agent. A nil *Rules means allow-all: no file, an empty file, or no matching group.

func Parse

func Parse(body []byte, userAgent string) *Rules

Parse parses a robots.txt body and returns the rules for userAgent, matched case-insensitively as a prefix and falling back to the * group. It strips a leading UTF-8 BOM, tolerates malformed lines, and reads at most MaxBytes. A nil result means allow-all.

func (*Rules) Allowed

func (r *Rules) Allowed(path string) bool

Allowed reports whether path may be fetched. path is a percent-decoded URL path such as "/a/b?x=1". A nil receiver allows everything. The decision is the longest-match rule, with an Allow winning a tie against an equally long Disallow.

func (*Rules) CrawlDelay

func (r *Rules) CrawlDelay() time.Duration

CrawlDelay returns the group's Crawl-delay, or 0 when none was published.

func (*Rules) Sitemaps

func (r *Rules) Sitemaps() []string

Sitemaps returns the absolute sitemap URLs named by Sitemap: lines. These are file-global in robots.txt, not per-group.

Jump to

Keyboard shortcuts

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