Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ClientHintFormFactors = map[string]string{
"automotive": "car browser",
"xr": "wearable",
"watch": "wearable",
"mobile": "smartphone",
"tablet": "tablet",
"desktop": "desktop",
"eink": "tablet",
}
ClientHintFormFactors maps client hint form factors to device types. Used when client hints provide explicit device type information.
PHP: AbstractDeviceParser::$clientHintFormFactorsMapping
Functions ¶
func GetDeviceTypeFromFormFactor ¶
GetDeviceTypeFromFormFactor returns the device type for a client hints form factor. Returns empty string if the form factor is not recognized.
func HasClientHintsFragment ¶
HasClientHintsFragment returns true if the user agent uses the Android client hints format. This is detected by the "Android 10+; K" pattern that Chromium uses for privacy.
Special case: Telegram-Android spoofs this pattern, so we exclude it.
PHP: AbstractDeviceParser::hasUserAgentClientHintsFragment()
func HasDesktopFragment ¶
HasDesktopFragment returns true if the user agent appears to be from a desktop browser. When true, mobile device parsing should be skipped entirely.
PHP: AbstractDeviceParser::hasDesktopFragment()
func RestoreUserAgent ¶
func RestoreUserAgent(ua string, ch *clienthints.ClientHints) string
RestoreUserAgent injects client hints data (device model, OS version) back into the UA string. This allows YAML regex patterns to match against the reconstructed UA.
PHP: AbstractDeviceParser::restoreUserAgentFromClientHints()
Types ¶
type Entry ¶
type Entry struct {
Brand string // Brand name (YAML key)
Regex string // Brand-level regex pattern
Device string // Default device type (smartphone, tablet, phablet, feature phone)
Model string // Brand-level model template (optional, uses $1..$n substitution)
Models []Model // Model-specific patterns (optional)
// contains filtered or unexported fields
}
Entry represents a brand's device patterns from mobiles.yml. Each entry contains a brand-level regex and optional model-specific sub-patterns.
func (*Entry) GetPosition ¶
GetPosition implements common.OrderedPattern.
func (*Entry) SetPosition ¶
SetPosition implements common.OrderedPattern.
type Match ¶
type Match struct {
Type string // Device type: smartphone, tablet, phablet, feature phone
Brand string // Device brand (manufacturer)
Model string // Device model name
}
Match represents a successful device detection result.
type Model ¶
type Model struct {
Regex string // Model-specific regex pattern
Model string // Model name template ($1..$n substitution)
Brand string // Override brand (optional)
Device string // Override device type (optional)
}
Model represents a specific model pattern within a brand. Models can override the parent brand's device type and even the brand name.
type Option ¶
type Option func(*Parser)
Option is a functional option for configuring Parser behavior.
func WithClientHints ¶
func WithClientHints(ch *clienthints.ClientHints) Option
WithClientHints enables client hints for device detection.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser parses a single user agent for mobile device information. Created via ParserFactory.NewParser() - do not instantiate directly.
type ParserFactory ¶
type ParserFactory struct {
// contains filtered or unexported fields
}
ParserFactory holds pre-compiled matchers and creates Parser instances. Thread-safe for concurrent use - create once, use from multiple goroutines.
func NewDefaultParserFactory ¶
func NewDefaultParserFactory() (*ParserFactory, error)
NewDefaultParserFactory is an alias for NewParserFactory kept for compatibility.
func NewParserFactory ¶
func NewParserFactory(opts ...common.FactoryOption) (*ParserFactory, error)
NewParserFactory loads and compiles the mobile regex DB from YAML. This is a large file (~45K lines, ~2000 brands) - loading takes a few seconds.
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) *Match
Parse is a convenience method that creates a parser and immediately parses.
func (*ParserFactory) Stats ¶
func (f *ParserFactory) Stats() common.IndexStats
Stats returns index statistics for debugging/monitoring.