Documentation
¶
Index ¶
- Constants
- func Init(opts ...Option) error
- type BotCategory
- type BotInfo
- type Browser
- type ClientHints
- type ClientType
- type Device
- type IABInfo
- type NativeApp
- type OS
- type Option
- type Parser
- func (p *Parser) Database() *db.Database
- func (p *Parser) DetectType(ua string) ClientType
- func (p *Parser) LookupAndroidModel(modelID string) (db.AndroidDevice, bool)
- func (p *Parser) LookupAppleModel(modelID string) (string, bool)
- func (p *Parser) Parse(ua string) *Result
- func (p *Parser) ParseWithHints(ua string, hints ClientHints) *Result
- type Result
Constants ¶
const ( OSiOS = "iOS" OSAndroid = "Android" OSWindows = "Windows" OSmacOS = "macOS" OSLinux = "Linux" OSDarwin = "Darwin" OSChromeOS = "Chrome OS" )
OS name constants.
const ( DeviceMobile = "mobile" DeviceTablet = "tablet" DeviceDesktop = "desktop" )
Device type constants.
const ( EngineBlink = "Blink" EngineWebKit = "WebKit" EngineGecko = "Gecko" EngineTrident = "Trident" EnginePresto = "Presto" )
Browser engine constants.
const ( ProductCFNetwork = "CFNetwork" ProductDarwin = "Darwin" ProductMozilla = "Mozilla" )
Well-known product/browser token names.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BotCategory ¶
type BotCategory string
BotCategory classifies what kind of bot this is.
const ( BotCategorySearch BotCategory = "search" BotCategorySocial BotCategory = "social" BotCategoryAI BotCategory = "ai" BotCategoryMonitor BotCategory = "monitor" BotCategoryScraper BotCategory = "scraper" )
type BotInfo ¶
type BotInfo struct {
Name string
Owner string
Category BotCategory
Confidence float64 // 0.0-1.0
}
BotInfo holds information about a detected bot.
type Browser ¶
type Browser struct {
Name string // "Chrome", "Safari", "Firefox"
Version string // "120.0.0.0"
Engine string // "Blink", "WebKit", "Gecko"
}
Browser holds parsed browser information.
type ClientHints ¶
type ClientHints struct {
UA string // Sec-CH-UA: "Chromium";v="120", "Google Chrome";v="120"
Mobile bool // Sec-CH-UA-Mobile: ?0
Platform string // Sec-CH-UA-Platform: "Windows"
PlatformVersion string // Sec-CH-UA-Platform-Version: "15.0.0"
FullVersionList string // Sec-CH-UA-Full-Version-List
Model string // Sec-CH-UA-Model
Architecture string // Sec-CH-UA-Arch
}
ClientHints represents the Client Hints headers sent by modern browsers as a replacement for the frozen User-Agent string. These values take priority over data parsed from the UA string.
func (ClientHints) IsEmpty ¶
func (ch ClientHints) IsEmpty() bool
type ClientType ¶
type ClientType uint8
ClientType indicates the category of the user agent. Each type implies which fields in Result are populated:
ClientTypeBrowser — Browser + OS + Device ClientTypeIAB — Browser + OS + Device + IAB ClientTypeNativeApp — OS + Device + Native ClientTypeHttpClient — Native only ClientTypeBot — Bot only ClientTypeUnknown — all fields empty
const ( ClientTypeBrowser ClientType = iota // Browser + OS + Device ClientTypeIAB // Browser + OS + Device + IAB ClientTypeNativeApp // OS + Device + Native ClientTypeHttpClient // Native only ClientTypeBot // Bot only ClientTypeUnknown // all fields empty )
func DetectType ¶
func DetectType(ua string) ClientType
DetectType detects the client type. Init must be called first.
type Device ¶
type Device struct {
Type string // "mobile", "tablet", "desktop", "tv", "console"
Model string // "iPhone 13 Pro" — may be empty
ModelRaw string // "iPhone14,2", "SM-G991B" — raw identifier
}
Device holds parsed device information.
type IABInfo ¶
type IABInfo struct {
App string
AppVersion string
Locale string
Region string
NetType string
ScreenScale float64
Resolution string
}
IABInfo holds in-app browser metadata from Facebook/Instagram/TikTok UAs.
type NativeApp ¶
type NativeApp struct {
Name string // "curl", "Dart", "CFNetwork", "ut-1"
Version string
Runtime string // "dart:io", "CFNetwork", "OkHttp"
}
NativeApp holds information about a native HTTP client or app.
type OS ¶
type OS struct {
Name string // "iOS", "Android", "Windows", "macOS"
Version string // "18.7", "14", "11"
Build string // "23A355" — real iOS build from the Mobile/ token; empty outside iOS and for frozen Safari
}
OS holds parsed operating system information.
type Option ¶
type Option func(*parserConfig)
Option configures how NewParser loads data.
func WithDataDir ¶
WithDataDir loads data exclusively from the given directory, ignoring embedded defaults. Use this when you maintain your own complete set of data files.
func WithOverrides ¶
WithOverrides merges user data on top of embedded defaults. The override directory may contain any subset of the data files (bots.json, apple.json, android.json, darwin.json). Only files that exist are merged; missing files are skipped. For device/bot data, override entries are added to or replace the built-in entries.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser holds the in-memory database and pipeline for UA parsing. Create with NewParser, then call Parse/ParseWithHints/DetectType.
func NewParser ¶
NewParser creates a ready-to-use parser.
Without options, it uses the embedded default data (zero-config):
p, err := herald.NewParser()
With WithDataDir, it loads data exclusively from the given directory:
p, err := herald.NewParser(herald.WithDataDir("path/to/data"))
With WithOverrides, it uses embedded defaults and merges user data on top:
p, err := herald.NewParser(herald.WithOverrides("path/to/overrides"))
func (*Parser) DetectType ¶
func (p *Parser) DetectType(ua string) ClientType
DetectType is a fast path that only determines the client type without full parsing of browser/OS/device details.
func (*Parser) LookupAndroidModel ¶
func (p *Parser) LookupAndroidModel(modelID string) (db.AndroidDevice, bool)
LookupAndroidModel looks up an Android model (e.g., "SM-G991B") → brand + model.
func (*Parser) LookupAppleModel ¶
LookupAppleModel looks up an Apple model identifier (e.g., "iPhone14,2") → human name.
func (*Parser) ParseWithHints ¶
func (p *Parser) ParseWithHints(ua string, hints ClientHints) *Result
ParseWithHints parses a UA string and enriches the result with Client Hints.
type Result ¶
type Result struct {
Raw string
ClientType ClientType
Browser Browser
OS OS
Device Device
IAB IABInfo
Bot BotInfo
Native NativeApp
}
Result is the parsed representation of a User-Agent string. All fields are value types — use IsEmpty() to check if a section was populated.
func ParseWithHints ¶
func ParseWithHints(ua string, hints ClientHints) *Result
ParseWithHints parses a UA string with Client Hints. Init must be called first.