useragent

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

Library
Go
vv1.3.5
546 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
38 /100 Needs Attention
Development Activity 0
Maintenance 20
Community 52
Maturity 60
Momentum 20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
60 /100 Good
Architecture 65
Code Quality 75
Innovation 55
Learning Curve 45

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

File Storage · Hosting Control Panel

37,294

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

View details
62
Repo Health
71
Technical
65
Dependency
Built with
Go 90%
Updated 1 weeks ago
Go
69%
Other

Hanko

Authentication · Security

9,038

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
66
Dependency
Built with
Go 69%
TypeScript 27%
Updated 3 days ago
Go
82%
GPL 3.0

Navidrome

File Storage · Music Audio

24,068

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

View details
91
Repo Health
81
Technical
69
Dependency
Built with
Go 82%
JavaScript 15%
Updated yesterday
Go
79%
MIT

seonaut

Developer Tools · Marketing

805

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
58
Repo Health
77
Technical
67
Dependency
Built with
Go 79%
HTML 17%
Updated 2 days ago
Go
54%
AGPL 3.0

Uptrace

Devops · Monitoring

4,300

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

View details
71
Repo Health
70
Technical
65
Dependency
Built with
Go 54%
Vue 34%
Updated 2 days ago
Go
79%
MIT

Wakapi

Analytics · Developer Tools

4,448

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

View details
89
Repo Health
77
Technical
72
Dependency
Built with
Go 79%
HTML 12%
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