User agent string parser in golang
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
James Mills d249fe7921
Fix module package name
2 weeks ago
.drone.yml Add Drone CI config 2 weeks ago
COPYING s 7 years ago
README.md Add Drone CI badge to README 2 weeks ago
browser.go Fix dependencies 2 weeks ago
crawler.go Add support for Googlebot News 5 years ago
go.mod Fix module package name 2 weeks ago
go.sum Fix dependencies 2 weeks ago
lex.go fixes #5 + cleanup 5 years ago
lex_test.go fixes #5 + cleanup 5 years ago
parse.go Fix dependencies 2 weeks ago
parse_test.go Fix dependencies 2 weeks ago

README.md

User agent parsing

Build Status

useragent is a library written in golang to parse user agent strings.

Usage

First install the library with:

go get git.mills.io/prologic/useragent

useragent is simple to use. First parse a string with useragent.Parse and then access the fields of useragent.UserAgent for the required information. Example:

See godoc for the complete documentation.

How it works?

      Lasciate ogne speranza, voi ch'intrate. -Dante

Parsing user agent strings is a hell. There is no standard for user agent strings, so useragent must use some heuristics. The site http://www.useragentstring.com/ has been invaluable during development. Some relevant links are also:

for the supported user agents see:

If you think useragent doesn't parse correctly a particular user agent string, just open an issue :).

Why this library?

useragent doesn't just split the user agent string and look for specific strings like other parsers, but it has specific parser for the most common browsers/crawlers and falls back to a generic parser for everything else. Its main features are:

  • Simple and stable API.
  • High precision in detection of the most common browsers/crawlers.
  • Detects mobile/tablet devices.
  • OS detection.
  • URL with more information about the user agent (usually it's the home page).
  • Security level detection when reported by browsers.

Who?

Thanks a lot to @brendanwalters (from http://pendo.io) for the contributions.

Donate!

License

useragent is released under the GPLv3 or later, see COPYING.