Documentation
¶
Index ¶
- type BotResult
- type ClientResult
- type DeviceDetectorOptions
- type DeviceDetectorResult
- type DeviceResult
- type DeviceType
- type OperatingSystemResult
- type Parser
- func NewBotDetector(options DeviceDetectorOptions) (parser Parser, err error)
- func NewDeviceDetector(options DeviceDetectorOptions) (parser Parser, err error)
- func NewDeviceParser(options DeviceDetectorOptions) (parser Parser)
- func NewOperatingSystemParser() (parser Parser)
- func NewVendorFragmentParser() (parser Parser)
- type VersionTruncation
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClientResult ¶
type DeviceDetectorOptions ¶
type DeviceDetectorOptions struct {
SkipBotDetection bool
VersionTruncation VersionTruncation
}
type DeviceDetectorResult ¶
type DeviceDetectorResult struct {
Client ClientResult `json:"client"`
Device DeviceResult `json:"device"`
OS OperatingSystemResult `json:"os"`
Bot BotResult `json:"bot"`
}
type DeviceResult ¶
type DeviceResult struct {
Type DeviceType `json:"type"`
Brand string `json:"brand"`
Model string `json:"model"`
}
type DeviceType ¶
type DeviceType string
const ( DeviceTypeDesktop DeviceType = "desktop" DeviceTypeSmartphone DeviceType = "smartphone" DeviceTypeTablet DeviceType = "tablet" DeviceTypeTelevision DeviceType = "television" DeviceTypeSmartDisplay DeviceType = "smart display" DeviceTypeCamera DeviceType = "camera" DeviceTypeCar DeviceType = "car" DeviceTypeConsole DeviceType = "console" DeviceTypePortableMediaPlayer DeviceType = "portable media player" DeviceTypePhablet DeviceType = "phablet" DeviceTypeWearable DeviceType = "wearable" DeviceTypeSmartSpeaker DeviceType = "smart speaker" DeviceTypeFeaturePhone DeviceType = "feature phone" DeviceTypePeripheral DeviceType = "peripheral" )
type OperatingSystemResult ¶
type Parser ¶
type Parser struct {
Parse func(userAgent string) (result interface{}, err error)
// contains filtered or unexported fields
}
Parser is a device detector parser.
func NewBotDetector ¶
func NewBotDetector(options DeviceDetectorOptions) (parser Parser, err error)
NewBotDetector creates a new bot detector with options.
func NewDeviceDetector ¶
func NewDeviceDetector(options DeviceDetectorOptions) (parser Parser, err error)
NewDeviceDetector creates a new device detector.
Example ¶
ExampleDeviceDetector shows how to use the device detector.
userAgent := "Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.96 Mobile Safari/537.36"
detector, err := NewDeviceDetector(DeviceDetectorOptions{})
if err != nil {
fmt.Printf("failed to create device detector: %v", err)
}
result, err := detector.Parse(userAgent)
if err != nil {
fmt.Printf("failed to parse user agent: %v", err)
}
if result == nil {
fmt.Printf("result is nil")
}
if result == "" {
fmt.Printf("result is empty")
}
fmt.Printf("%s\n", result)
Output: {"client":{"type":"browser","name":"Chrome Mobile","version":"41.0","engine":"Blink","engineVersion":""},"os":{"name":"Android","version":"6.0","platform":""},"device":{"type":"smartphone","brand":"Google","model":"Nexus 5X"},"bot":null}
func NewDeviceParser ¶
func NewDeviceParser(options DeviceDetectorOptions) (parser Parser)
NewDeviceParser creates a new device parser with options
func NewOperatingSystemParser ¶
func NewOperatingSystemParser() (parser Parser)
NewOperatingSystemParser creates a new operating system parser.
func NewVendorFragmentParser ¶
func NewVendorFragmentParser() (parser Parser)
NewVendorFragmentParser creates a new vendor fragment parser.
type VersionTruncation ¶
type VersionTruncation int
const ( VC VersionTruncation = iota VC1 VC2 VC3 )
Click to show internal directories.
Click to hide internal directories.