Documentation
¶
Index ¶
- Constants
- Variables
- func IsDigit(r rune) bool
- func IsLetter(r rune) bool
- func RemoveAndroidIdentifiers(ua string) string
- func RemoveMobileIdentifiers(ua string) string
- func RemoveVersions(ua string) string
- func ReplaceIndexes(ua string, indexes []int) string
- type Match
- type MatchResults
- type MatchType
Constants ¶
const ( Unknown Match = iota // There is no match token for Android Browser, but the absence of any browser token paired with Android is a good indicator of this browser. BrowserAndroid BrowserChrome BrowserEdge BrowserFirefox BrowserIE BrowserOpera BrowserOperaMini BrowserSafari BrowserVivaldi BrowserSamsung BrowserSilk BrowserFalkon BrowserNintendo BrowserYandex OSAndroid OSChromeOS OSIOS OSLinux OSFreeBSD OSOpenBSD OSMacOS OSWindows DeviceDesktop DeviceMobile DeviceTablet DeviceTV DeviceBot TokenVersion // We need a separate type for mobile devices since some user agents use "Mobile/" // appended with a device ID. We need to handle these separately to strip those IDs // out. TokenMobileDevice MatchUnknown MatchType = iota MatchBrowser MatchOS MatchDevice MatchVersion )
Variables ¶
var MatchPrecedenceMap = map[Match]uint8{
BrowserSafari: 1,
BrowserAndroid: 2,
BrowserChrome: 3,
BrowserFirefox: 4,
BrowserIE: 5,
BrowserOpera: 6,
BrowserOperaMini: 7,
BrowserEdge: 8,
BrowserVivaldi: 9,
BrowserSamsung: 10,
BrowserSilk: 11,
BrowserFalkon: 12,
BrowserNintendo: 13,
BrowserYandex: 14,
OSLinux: 1,
OSAndroid: 2,
OSIOS: 3,
OSFreeBSD: 4,
OSOpenBSD: 5,
OSChromeOS: 5,
OSMacOS: 6,
OSWindows: 7,
DeviceDesktop: 1,
DeviceMobile: 2,
TokenMobileDevice: 3,
DeviceTablet: 4,
DeviceTV: 5,
DeviceBot: 6,
}
MatchPrecedenceMap is a map of user agent types to their importance in determining what is the actual browser/device/OS being used.
For example, Chrome user agents also contain the string "Safari" at the end of the user agent. This means that if we only check for "Safari" first, we will incorrectly determine the browser to be Safari instead of Chrome.
By setting a precedence, we can determine which match is more important and use that as the final result.
Functions ¶
func IsDigit ¶
IsDigit reports whether the rune is a decimal digit.
This is an optimised version of unicode.IsDigit without the check for r <= unicode.MaxLatin1.
func IsLetter ¶
IsLetter reports whether the rune is a letter in ASCII.
This is an optimised version of unicode.IsLetter without the check for r <= unicode.MaxLatin1.
func RemoveAndroidIdentifiers ¶
RemoveAndroidIdentifiers removes the device identifiers from the user agent string. This specifically removes any strings that follow the Android tokens.
func RemoveMobileIdentifiers ¶
RemoveMobileIdentifiers removes the device identifiers from the user agent string. This specifically removes any strings that follow the Mobile tokens. For example, "Mobile/14F89" should be "Mobile".
func RemoveVersions ¶
RemoveVersions removes the version numbers from the user agent string.
func ReplaceIndexes ¶
ReplaceIndexes replaces the runes at the given indexes with empty strings.
Types ¶
type Match ¶ added in v1.0.3
type Match uint8
Match is an enum for the browser, os or device name.
func (Match) GetMatchBrowser ¶ added in v1.1.0
GetMatchBrowser returns the browser name of a match.
func (Match) GetMatchDevice ¶ added in v1.1.0
GetMatchDevice returns the device name of a match.
func (Match) GetMatchName ¶ added in v1.1.0
GetMatchName returns the name of a match. This is used for debugging in tests.
func (Match) GetMatchOS ¶ added in v1.1.0
GetMatchOS returns the OS name of a match.
func (Match) GetMatchType ¶ added in v1.1.0
GetMatchType returns the match type of a match result using the MatchPrecedenceMap.
type MatchResults ¶
type MatchResults struct { Match Match MatchType MatchType // Precedence value for each result type to determine which result should be overwritten. // Higher values overwrite lower values. Precedence uint8 EndIndex int }
MatchResults contains the information from MatchTokenIndexes.
func MatchTokenIndexes ¶
func MatchTokenIndexes(ua string) []MatchResults
MatchTokenIndexes finds the start and end indexes of necessary tokens that match a known browser, device, or OS. This is used to determine when to insert a result value into the trie.