useragent

A dependency-free Go library for parsing browser, OS, device, and bot data out of User-Agent strings.

Library
Go
vv1.3.5
545stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
40/100Fair
Development Activity0
Maintenance20
Community52
Maturity60
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
60/100Good
Architecture65
Code Quality75
Innovation55
Learning Curve45

useragent is a lightweight Go package for parsing HTTP User-Agent strings into structured data: browser name and version, operating system and version, and device type (mobile, tablet, desktop, or bot). It exposes a single Parse function built on a hand-written, deterministic tokenizer rather than a large external regex database, so it stays fast under heavy production traffic.

Beyond the raw fields, the package adds convenience methods like IsChrome(), IsAndroid(), and IsGooglebot() for common comparisons, plus a VersionNo struct that breaks version strings into Major/Minor/Patch integers for numeric comparisons such as checking whether a browser is below a minimum supported version. The author runs it in production on high-traffic sites, including their own analytics service, and continues to extend bot and browser coverage from community-reported edge cases.

What You Get

  • A Parse(userAgent string) UserAgent function returning a struct with Name, Version, OS, OSVersion, Device, and boolean Mobile/Tablet/Desktop/Bot flags
  • Shorthand boolean methods like IsChrome(), IsAndroid(), IsGooglebot(), and IsSafari() for readable conditional checks instead of raw string comparisons
  • A VersionNo struct with Major/Minor/Patch integers plus VersionNoShort()/VersionNoFull() and OSVersionNoShort()/OSVersionNoFull() helpers for numeric version comparisons
  • Built-in detection for major bots (Googlebot, Bingbot, YandexBot, Applebot, Twitterbot, AdsBot) and in-app browsers (Facebook, Instagram, TikTok)

Common Use Cases

  • Analytics pipelines - tagging incoming requests with browser/OS/device type for dashboards without a heavyweight geo/UA service
  • Bot filtering - excluding crawler and bot traffic from real-user metrics using the Bot flag and IsGooglebot()/IsTwitterbot() helpers
  • Feature gating by browser version - using VersionNo.Major to redirect or warn users on outdated browsers
  • Responsive server-side rendering - branching HTML output for mobile vs. tablet vs. desktop using the Mobile/Tablet/Desktop flags

Under The Hood

Architecture The package is a single flat useragent module split across three files: ua.go (the tokenizer and Parse entry point), is.go (boolean convenience methods on UserAgent), and version.go (VersionNo parsing/formatting). There is no layering, dependency injection, or exported interface beyond Parse itself — the private tokenizer (parse, properties, property) walks the raw string once into a flat list of key/value tokens, and Parse then runs two large sequential switch statements (OS lookup, then browser/bot name lookup) against those tokens, falling back to helper functions like findBestMatch, findAndroidDevice, and findMacOSVersion for ambiguous cases. Data flows one-directionally from raw string to tokens to the UserAgent struct within a single call; because both switch statements and the resolution helpers share assumptions about token shape, changing the tokenizer’s output format would ripple through nearly the whole file.

Tech Stack The implementation uses only the Go standard library (bytes, regexp, strings, strconv, fmt) with zero third-party dependencies — go.sum is empty. go.mod targets Go 1.14 and there is no build tooling beyond go build/go test, and no CI workflow config in the repository.

Code Quality Testing relies on two table-driven test functions (TestParse, TestSingle) backed by a roughly 26KB table of real-world User-Agent strings covering dozens of browsers, operating systems, devices, and bots, run via the standard testing package with no additional assertion library. Error handling is minimal by design: parseVersion silently returns a zero-value VersionNo on a non-numeric segment rather than surfacing an error, which is a reasonable tradeoff for a parser that must never fail on malformed input, but means version parsing failures are invisible to callers. There is no linter or formatter configuration checked in, and naming is consistent and idiomatic Go throughout.

What Makes It Unique Rather than matching against a large external database of regex signatures (the common approach used by many UA-parsing libraries), this package hand-tokenizes the string once and classifies it with explicit switch/case logic tuned against real-world traffic, prioritizing raw parsing speed and a small dependency-free footprint over exhaustive device-database coverage. The VersionNo struct is a small but practical differentiator, giving callers numeric version components without needing to hand-parse the Version string themselves.

Used by 6 apps in this directory

Go
90%
Apache 2.0

CasaOS

Hosting Control Panel · File Storage

37,163

Your simple, elegant personal cloud OS for home data and apps

View details
51
Repo Health
71
Technical
65
Dependency
Built with
Go90%
Updated 1 years ago
Go
65%
Other

Hanko

Security · Authentication

9,016

Open source, self-hostable authentication platform with passkeys, SAML SSO, and OAuth — the privacy-first alternative to Auth0 and Clerk.

View details
89
Repo Health
81
Technical
69
Dependency
Built with
Go65%
TypeScript30%
Updated 2 days ago
Go
81%
GPL 3.0

Navidrome

File Storage

23,217

Run your own personal Spotify — stream your entire music collection from any device, anywhere, forever.

View details
91
Repo Health
81
Technical
70
Dependency
Built with
Go81%
JavaScript15%
Updated today
Go
79%
MIT

seonaut

Marketing · Developer Tools

776

Self-hosted SEO auditing that crawls your entire website and surfaces critical issues — broken links, duplicate meta tags, redirect loops, and more — before they hurt your rankings.

View details
43
Repo Health
77
Technical
68
Dependency
Built with
Go79%
HTML17%
Updated 3 months ago
Go
54%
AGPL 3.0

Uptrace

Monitoring · Devops

4,274

Unified open-source APM that collects OpenTelemetry traces, metrics, and logs into a single self-hosted platform backed by ClickHouse.

View details
63
Repo Health
70
Technical
66
Dependency
Built with
Go54%
Vue34%
Updated 2 weeks ago
Go
78%
MIT

Wakapi

Developer Tools · Analytics

4,413

Self-hosted WakaTime-compatible coding statistics backend that gives developers full control over their coding activity data.

View details
89
Repo Health
77
Technical
73
Dependency
Built with
Go78%
HTML12%
Updated 3 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search