Documentation
¶
Overview ¶
Package detector provides the main DeviceDetector that orchestrates bot, client, and device detection.
Index ¶
- Variables
- type BotInfo
- type BotProducer
- type ClientInfo
- type ClientMatch
- type DeviceDetector
- type DeviceInfo
- type DeviceType
- type FullInfo
- type FullInfoClient
- type FullInfoDevice
- type FullInfoOS
- type OSInfo
- type Option
- type ParseResult
- func (r *ParseResult) GetBot() *bots.BotMatch
- func (r *ParseResult) GetBrand() string
- func (r *ParseResult) GetClient() *ClientMatch
- func (r *ParseResult) GetDevice() DeviceType
- func (r *ParseResult) GetFullInfo() *FullInfo
- func (r *ParseResult) GetModel() string
- func (r *ParseResult) GetOS() *operatingsystem.Match
- func (r *ParseResult) IsBot() bool
- func (r *ParseResult) IsDesktop() bool
- func (r *ParseResult) IsMobile() bool
- func (r *ParseResult) IsTV() bool
- func (r *ParseResult) IsTablet() bool
- func (r *ParseResult) IsWearable() bool
- type Result
Constants ¶
This section is empty.
Variables ¶
var DeviceTypeNames = map[DeviceType]string{ DeviceTypeDesktop: "desktop", DeviceTypeSmartphone: "smartphone", DeviceTypeTablet: "tablet", DeviceTypeFeaturePhone: "feature phone", DeviceTypeConsole: "console", DeviceTypeTV: "tv", DeviceTypeCarBrowser: "car browser", DeviceTypeSmartDisplay: "smart display", DeviceTypeCamera: "camera", DeviceTypePortableMediaPlayer: "portable media player", DeviceTypePhablet: "phablet", DeviceTypeSmartSpeaker: "smart speaker", DeviceTypeWearable: "wearable", DeviceTypePeripheral: "peripheral", }
DeviceTypeNames maps device type constants to their string names.
Functions ¶
This section is empty.
Types ¶
type BotInfo ¶
type BotInfo struct {
Name string
Category string
URL string
Producer *BotProducer
}
BotInfo contains information about a detected bot.
type BotProducer ¶
BotProducer contains information about a bot's producer.
type ClientInfo ¶
type ClientInfo struct {
Type string // browser, mobile app, feed reader, etc.
Name string
Version string
Engine string
}
ClientInfo contains information about the detected client (browser, app, etc.).
type ClientMatch ¶
type ClientMatch struct {
Type string // browser, mobile app, feed reader, library, media player, pim
Name string
Version string
Engine string // only for browsers
EngineVersion string // only for browsers
Family string // only for browsers (but excluded from testParseClient comparison)
}
ClientMatch is a unified client match type that can hold results from any client parser. This is used by the DeviceDetector to return client detection results.
type DeviceDetector ¶
type DeviceDetector struct {
// contains filtered or unexported fields
}
DeviceDetector is the main orchestrator for user agent parsing.
func New ¶
func New(opts ...Option) (*DeviceDetector, error)
New creates a new DeviceDetector with all parsers loaded from embedded regex YAMLs.
func NewDefault ¶
func NewDefault(opts ...Option) (*DeviceDetector, error)
NewDefault creates a DeviceDetector with default options (alias for New).
func (*DeviceDetector) Parse ¶
func (d *DeviceDetector) Parse(ua string, ch *clienthints.ClientHints) *ParseResult
Parse parses a user agent string and returns the result.
type DeviceInfo ¶
type DeviceInfo struct {
Type DeviceType
Brand string
Model string
}
DeviceInfo contains information about the detected device.
type DeviceType ¶
type DeviceType int
DeviceType represents the detected device type.
const ( DeviceTypeDesktop DeviceType = 0 DeviceTypeSmartphone DeviceType = 1 DeviceTypeTablet DeviceType = 2 DeviceTypeFeaturePhone DeviceType = 3 DeviceTypeConsole DeviceType = 4 DeviceTypeTV DeviceType = 5 DeviceTypeCarBrowser DeviceType = 6 DeviceTypeSmartDisplay DeviceType = 7 DeviceTypeCamera DeviceType = 8 DeviceTypePortableMediaPlayer DeviceType = 9 DeviceTypePhablet DeviceType = 10 DeviceTypeSmartSpeaker DeviceType = 11 DeviceTypeWearable DeviceType = 12 DeviceTypePeripheral DeviceType = 13 DeviceTypeUnknown DeviceType = -1 )
func DeviceTypeFromString ¶
func DeviceTypeFromString(s string) DeviceType
DeviceTypeFromString converts a string device type to DeviceType constant.
type FullInfo ¶
type FullInfo struct {
UserAgent string `yaml:"user_agent"`
OS *FullInfoOS `yaml:"os"`
Client *FullInfoClient `yaml:"client"`
Device *FullInfoDevice `yaml:"device"`
OSFamily string `yaml:"os_family"`
BrowserFamily string `yaml:"browser_family"`
}
FullInfo is the complete detection result matching PHP's getInfoFromUserAgent() output. This is the structure used for the testParse integration test.
func GetInfoFromUserAgent ¶
func GetInfoFromUserAgent(dd *DeviceDetector, ua string, ch *clienthints.ClientHints) *FullInfo
GetInfoFromUserAgent is a convenience function matching PHP's DeviceDetector::getInfoFromUserAgent(). It creates a DeviceDetector, parses the UA, and returns the full info structure.
type FullInfoClient ¶
type FullInfoClient struct {
Type string `yaml:"type"`
Name string `yaml:"name"`
Version string `yaml:"version"`
Engine string `yaml:"engine"`
EngineVersion string `yaml:"engine_version"`
}
FullInfoClient matches the PHP client output structure.
type FullInfoDevice ¶
type FullInfoDevice struct {
Type string `yaml:"type"`
Brand string `yaml:"brand"`
Model string `yaml:"model"`
}
FullInfoDevice matches the PHP device output structure.
type FullInfoOS ¶
type FullInfoOS struct {
Name string `yaml:"name"`
Version string `yaml:"version"`
Platform string `yaml:"platform"`
}
FullInfoOS matches the PHP os output structure.
type Option ¶
type Option func(*DeviceDetector)
Option configures the DeviceDetector.
func WithDiscardBotInformation ¶
func WithDiscardBotInformation() Option
WithDiscardBotInformation discards detailed bot information.
func WithFactoryOptions ¶
func WithFactoryOptions(opts ...common.FactoryOption) Option
WithFactoryOptions allows passing factory options directly to all parser factories.
func WithIndexOnly ¶
func WithIndexOnly() Option
WithIndexOnly sets candidate mode to index-only (no full scan fallback) for all parser factories.
func WithRe2Only ¶
func WithRe2Only() Option
WithRe2Only sets regex mode to RE2-only for all parser factories.
func WithSkipBotDetection ¶
func WithSkipBotDetection() Option
WithSkipBotDetection skips bot detection.
type ParseResult ¶
type ParseResult struct {
// contains filtered or unexported fields
}
ParseResult contains the parsed detection result with helper methods.
func (*ParseResult) GetBot ¶
func (r *ParseResult) GetBot() *bots.BotMatch
GetBot returns the bot info if detected.
func (*ParseResult) GetBrand ¶
func (r *ParseResult) GetBrand() string
GetBrand returns the device brand.
func (*ParseResult) GetClient ¶
func (r *ParseResult) GetClient() *ClientMatch
GetClient returns the client info.
func (*ParseResult) GetDevice ¶
func (r *ParseResult) GetDevice() DeviceType
GetDevice returns the device type.
func (*ParseResult) GetFullInfo ¶
func (r *ParseResult) GetFullInfo() *FullInfo
GetFullInfo returns the complete detection result matching PHP's getInfoFromUserAgent() output. This includes user_agent, os, client, device, os_family, and browser_family.
func (*ParseResult) GetModel ¶
func (r *ParseResult) GetModel() string
GetModel returns the device model.
func (*ParseResult) GetOS ¶
func (r *ParseResult) GetOS() *operatingsystem.Match
GetOS returns the OS info.
func (*ParseResult) IsBot ¶
func (r *ParseResult) IsBot() bool
IsBot returns true if the user agent is a bot.
func (*ParseResult) IsDesktop ¶
func (r *ParseResult) IsDesktop() bool
IsDesktop returns true if the device is a desktop.
func (*ParseResult) IsMobile ¶
func (r *ParseResult) IsMobile() bool
IsMobile returns true if the device is mobile. PHP logic: mobile device types OR mobile-only browser OR (!bot && !desktop && known OS)
func (*ParseResult) IsTV ¶
func (r *ParseResult) IsTV() bool
IsTV returns true if the device is a TV.
func (*ParseResult) IsTablet ¶
func (r *ParseResult) IsTablet() bool
IsTablet returns true if the device is a tablet.
func (*ParseResult) IsWearable ¶
func (r *ParseResult) IsWearable() bool
IsWearable returns true if the device is a wearable.
type Result ¶
type Result struct {
Bot *BotInfo
Client *ClientInfo
OS *OSInfo
Device *DeviceInfo
}
Result contains the full detection result.