Help us shape the future of Go! Take the 2026 Go Developer Survey

robots

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package robots fetches robots.txt and answers RFC 9309 access questions.

Index

Constants

View Source
const MaxSize = 500 * 1024

MaxSize is the largest robots.txt body that is parsed. RFC 9309 requires crawlers to parse at least 500 KiB.

Variables

This section is empty.

Functions

func Audit added in v0.2.0

func Audit(ctx context.Context, cache *Cache, target string, ps []types.Profile) types.RobotsAudit

Audit checks every profile that has a robots.txt token against target.

func Directives added in v0.2.0

func Directives(h http.Header, body []byte, agent string) []string

Directives returns the indexing directives (noindex, nofollow, noai, ...) that apply to the robots.txt token agent, from X-Robots-Tag headers and <meta name="robots"> or <meta name="{agent}"> tags. Generic and agent-specific directives are merged without duplicates.

func URLFor

func URLFor(rawURL string) (string, error)

URLFor returns the robots.txt URL for the origin of rawURL.

Types

type Cache

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

Cache fetches robots.txt at most once per origin and is safe for concurrent use.

func NewCache

func NewCache(get Getter) *Cache

NewCache returns a Cache that fetches with get.

func (*Cache) Get

func (c *Cache) Get(ctx context.Context, target string) *Data

Get returns the robots.txt data for the origin of target.

type Data

type Data struct {
	URL     string `json:"url"`
	Status  int    `json:"status"`
	Content string `json:"-"`
	// Err is set when robots.txt could not be fetched or returned 5xx.
	Err error `json:"-"`
}

Data is the robots.txt state for one origin.

func (*Data) Allowed

func (d *Data) Allowed(agent, rawURL string) bool

Allowed reports whether agent may fetch rawURL.

func (*Data) ContentSignals added in v0.2.0

func (d *Data) ContentSignals(agent string) map[string]string

ContentSignals returns the Content-Signal directives (https://contentsignals.org) that apply to agent, such as {"search": "yes", "ai-train": "no"}. It returns nil when there are none.

func (*Data) Sitemaps added in v0.2.0

func (d *Data) Sitemaps() []string

Sitemaps returns the sitemap URLs listed in robots.txt.

func (*Data) Unreachable

func (d *Data) Unreachable() bool

Unreachable reports whether robots.txt failed with a network error or a server error. RFC 9309 §2.3.1.4 says crawlers must then assume full disallow.

type Getter

type Getter func(ctx context.Context, url string) (status int, body []byte, err error)

Getter performs a GET request and returns the status code and body.

Jump to

Keyboard shortcuts

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