Documentation ¶
Overview ¶
Package useragent parses a user agent string.
Index ¶
Examples ¶
Constants ¶
View Source
const ( OSAndroid = "Android" OSMacOS = "Mac OS X" OSiOS = "iOS" OSLinux = "GNU/Linux" OSWindows = "Windows" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Security ¶
type Security int
Some browsers may put security level information in their user agent string.
type UserAgent ¶
type UserAgent struct { // The original user agent string. Original string Type Type // The browser/crawler/etc. name. For example: // Firefox, IceCat, Iceweasel // Dillo // Chrome // MSIE // Googlebot // etc. // If the name is not known, Name will be `unknown'. Name string Version semver.Version // The OS name. Can be one of: // GNU/Linux // FreeBSD // OpenBSD // NetBSD // Windows // Mac OS X // Android // Firefox OS // CrOS // etc. // If the os is not known, OS will be `unknown'. OS string OSVersion semver.Version Security Security // URL with more information about the user agent (in most cases it's the home page). // If unknown is nil. URL *url.URL // Is it a phone device? Mobile bool // Is it a tablet device? Tablet bool }
func Parse ¶
Try to extract information about an user agent from uas. Since user agent strings don't have a standard, this function uses heuristics.
Example ¶
ua := Parse("Mozilla/5.0 (X11; Linux i686; rv:38.0) Gecko/20100101 Firefox/38.0") fmt.Print(ua)
Output: Type: Browser Name: Firefox Version: 38.0.0 OS: GNU/Linux OSVersion: 0.0.0 Security: Unknown security Mobile: false Tablet: false
Example (Access) ¶
ua := Parse("Mozilla/5.0 (X11; Linux i686; rv:38.0) Gecko/20100101 Firefox/38.0") if ua == nil { log.Fatal("cannot parse user agent string") } fmt.Println(ua.Type) fmt.Println(ua.Name) fmt.Println(ua.Version) fmt.Println(ua.OS) if ua.Security != SecurityUnknown { fmt.Println(ua.Security) }
Output: Browser Firefox 38.0.0 GNU/Linux
Click to show internal directories.
Click to hide internal directories.