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 ¶
GetPosition implements the common.OrderedPattern interface.
func (*BotEntry) SetPosition ¶
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) Parse ¶
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.