helper

package
v1.12.1 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: Unlicense Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GoogleCrawlerIPRangeURLs = []string{
	"https://developers.google.com/static/search/apis/ipranges/googlebot.json",
	"https://developers.google.com/static/crawling/ipranges/common-crawlers.json",
	"https://developers.google.com/static/crawling/ipranges/special-crawlers.json",
	"https://developers.google.com/static/crawling/ipranges/user-triggered-fetchers-google.json",
}

Functions

func FetchGoogleCrawlerIPs added in v1.12.1

func FetchGoogleCrawlerIPs(log *slog.Logger, httpClient *http.Client, urls []string) ([]string, error)

FetchGoogleCrawlerIPs fetches crawler IP ranges from multiple Google-managed endpoints, then returns a canonical, unique list where broader prefixes replace narrower prefixes.

func FetchGooglebotIPs added in v1.12.0

func FetchGooglebotIPs(log *slog.Logger, httpClient *http.Client, url string) ([]string, error)

FetchGooglebotIPs fetches the list of Googlebot IPs from Google's official endpoint, parses the JSON response, and returns a slice of CIDR strings.

func GetDefaultTmpl

func GetDefaultTmpl() string

need to hardcode a default template given yaegi's constraints on finding files on disk provided by this plugin

func GetPojJS added in v1.11.0

func GetPojJS() string

GetPojJS returns the proof-of-javascript JavaScript implementation

func IsIpExcluded

func IsIpExcluded(clientIP string, exemptIps []*net.IPNet) bool

func IsIpGoodBot

func IsIpGoodBot(clientIP string, goodBots []string) bool

func ParseCIDR

func ParseCIDR(cidr string) (*net.IPNet, error)

func ReduceCIDRs added in v1.12.1

func ReduceCIDRs(cidrs []string, log *slog.Logger) []string

ReduceCIDRs canonicalizes CIDRs, removes exact duplicates, and removes narrower ranges when they are fully covered by broader ranges.

func RefreshGoogleCrawlerIPs added in v1.12.1

func RefreshGoogleCrawlerIPs(log *slog.Logger, httpClient *http.Client, target *GooglebotIPs, urls []string) (int, error)

RefreshGoogleCrawlerIPs fetches crawler IPs from all configured URLs and updates the provided GooglebotIPs set. Returns the number of CIDRs loaded.

Types

type GooglebotIPs added in v1.12.0

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

GooglebotIPs holds the list of Googlebot IP ranges, providing a thread-safe way to check if an IP is a Googlebot.

func NewGooglebotIPs added in v1.12.0

func NewGooglebotIPs() *GooglebotIPs

NewGooglebotIPs creates and initializes a new GooglebotIPs object.

func (*GooglebotIPs) Contains added in v1.12.0

func (g *GooglebotIPs) Contains(ip net.IP) bool

Contains checks if the given IP address is within any of the stored Googlebot IP ranges.

func (*GooglebotIPs) Update added in v1.12.0

func (g *GooglebotIPs) Update(cidrs []string, log *slog.Logger)

Update parses a slice of CIDR strings and replaces the existing IP ranges with the new ones. It logs an error for any CIDR string that fails to parse.

Jump to

Keyboard shortcuts

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