bots

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: LGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package bots provides bot detection functionality for user agent parsing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BotEntry

type BotEntry struct {
	Regex    string    `yaml:"regex"`
	Name     string    `yaml:"name"`
	Category string    `yaml:"category,omitempty"`
	URL      string    `yaml:"url,omitempty"`
	Producer *Producer `yaml:"producer,omitempty"`
	// contains filtered or unexported fields
}

BotEntry represents a single bot definition from the YAML regex file.

func (*BotEntry) GetPosition

func (b *BotEntry) GetPosition() int

GetPosition implements the common.OrderedPattern interface.

func (*BotEntry) GetRegex

func (b *BotEntry) GetRegex() string

GetRegex implements the common.Pattern interface.

func (*BotEntry) SetPosition

func (b *BotEntry) SetPosition(pos int)

SetPosition implements the common.OrderedPattern interface.

type BotMatch

type BotMatch struct {
	Name     string    `json:"name"`
	Category string    `json:"category,omitempty"`
	URL      string    `json:"url,omitempty"`
	Producer *Producer `json:"producer,omitempty"`
}

BotMatch represents the result of a successful bot detection. This matches the PHP return structure.

type Option

type Option func(*Parser)

Option is a functional option for configuring Parser behavior.

func WithDiscardDetails

func WithDiscardDetails() Option

WithDiscardDetails enables discarding detailed bot info. When enabled, Parse() returns a minimal result instead of full bot info.

type Parser

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

Parser parses a single user agent for bot information. Created via ParserFactory.NewParser() - do not instantiate directly.

func (*Parser) IsBot

func (p *Parser) IsBot() bool

IsBot returns true if the user agent is detected as a bot.

func (*Parser) Parse

func (p *Parser) Parse() *BotMatch

Parse parses the user agent and checks for bot information.

Returns:

  • *BotMatch with full bot info if a bot is detected
  • nil if no bot is detected

If WithDiscardDetails() was used, returns a minimal BotMatch with only a placeholder name "true" instead of full info (matching PHP's [true] return).

type ParserFactory

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

ParserFactory holds pre-compiled regexes and creates Parser instances. Thread-safe for concurrent use - create once, use from multiple goroutines.

func NewParserFactory

func NewParserFactory(opts ...common.FactoryOption) (*ParserFactory, error)

NewParserFactory creates a factory by loading and compiling regexes from the embedded YAML DB.

func (*ParserFactory) IndexStats

func (f *ParserFactory) IndexStats() common.IndexStats

IndexStats returns statistics about the keyword index.

func (*ParserFactory) IsBot

func (f *ParserFactory) IsBot(ua string) bool

IsBot is a convenience method that checks if a user agent is a bot.

func (*ParserFactory) NewParser

func (f *ParserFactory) NewParser(ua string, opts ...Option) *Parser

NewParser creates a new Parser instance for parsing a single user agent.

func (*ParserFactory) Parse

func (f *ParserFactory) Parse(ua string, opts ...Option) *BotMatch

Parse is a convenience method that creates a parser and immediately parses.

type Producer

type Producer struct {
	Name string `yaml:"name"`
	URL  string `yaml:"url"`
}

Producer represents the producer/company that created the bot.

Jump to

Keyboard shortcuts

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