{"id":36828927,"url":"https://github.com/medama-io/go-useragent","last_synced_at":"2026-01-12T14:10:20.320Z","repository":{"id":207401554,"uuid":"717949930","full_name":"medama-io/go-useragent","owner":"medama-io","description":"Fast trie-based user-agent parser in Go.","archived":false,"fork":false,"pushed_at":"2025-12-21T14:05:45.000Z","size":1290,"stargazers_count":101,"open_issues_count":6,"forks_count":7,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-23T04:57:16.226Z","etag":null,"topics":["go","golang","ua-parser","user-agent","useragent"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/medama-io/go-useragent","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/medama-io.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":["ayuhito"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"lfx_crowdfunding":null,"polar":null,"buy_me_a_coffee":null,"thanks_dev":null,"custom":null}},"created_at":"2023-11-13T03:08:36.000Z","updated_at":"2025-12-23T01:06:20.000Z","dependencies_parsed_at":null,"dependency_job_id":"b16376a0-0b84-441e-aa0a-d71cd75d8862","html_url":"https://github.com/medama-io/go-useragent","commit_stats":null,"previous_names":["medama-io/go-useragent"],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/medama-io/go-useragent","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/medama-io%2Fgo-useragent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/medama-io%2Fgo-useragent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/medama-io%2Fgo-useragent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/medama-io%2Fgo-useragent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/medama-io","download_url":"https://codeload.github.com/medama-io/go-useragent/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/medama-io%2Fgo-useragent/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28340384,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T12:22:26.515Z","status":"ssl_error","status_checked_at":"2026-01-12T12:22:10.856Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","golang","ua-parser","user-agent","useragent"],"created_at":"2026-01-12T14:10:20.168Z","updated_at":"2026-01-12T14:10:20.302Z","avatar_url":"https://github.com/medama-io.png","language":"Go","funding_links":["https://github.com/sponsors/ayuhito"],"categories":[],"sub_categories":[],"readme":"# go-useragent\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/medama-io/go-useragent.svg)](https://pkg.go.dev/github.com/medama-io/go-useragent)\n\n`go-useragent` is a high-performance zero-allocation Go library designed to parse browser name and version, operating system, and device type information from user-agent strings with _sub-microsecond_ parsing times.\n\nIt achieves this efficiency by using a modified hybrid [trie](https://en.wikipedia.org/wiki/Trie) data structure to store and rapidly look up user-agent tokens. It utilizes heuristic rules, tokenizing a list of user-agent strings into a trie during startup. During runtime, the parsing process involves a straightforward lookup operation.\n\nThis project is actively maintained and used by the lightweight website analytics project [Medama](https://github.com/medama-io/medama).\n\n## Installation\n\n```bash\ngo get -u github.com/medama-io/go-useragent\n```\n\n## Usage\n\nThis type of parser is typically initialized once at application startup and reused throughout the application's lifecycle. While it doesn't offer the exhaustive coverage of traditional regex-based parsers, it can be paired with one to handle unknown edge cases, where the trie-based parser acts as a fast path for the majority of user-agents.\n\n## Example\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"github.com/medama-io/go-useragent\"\n)\n\nfunc main() {\n\t// Create a new parser. Initialize only once during application startup.\n\tua := useragent.NewParser()\n\n\t// Example user-agent string.\n\tstr := \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36\"\n\n\t// Parse the user-agent string.\n\tagent := ua.Parse(str)\n\n\t// Access parsed information using agent fields.\n\tfmt.Println(agent.Browser())        // agents.BrowserChrome\n\tfmt.Println(agent.BrowserVersion()) // 118.0.0.0\n\tfmt.Println(agent.OS())             // agents.OSWindows\n\tfmt.Println(agent.Device())         // agents.DeviceDesktop\n\n\t// Boolean helper functions.\n\tfmt.Println(agent.IsChrome())  // true\n\tfmt.Println(agent.IsFirefox()) // false\n\n\tfmt.Println(agent.IsWindows()) // true\n\tfmt.Println(agent.IsLinux())   // false\n\n\tfmt.Println(agent.IsDesktop()) // true\n\tfmt.Println(agent.IsTV())      // false\n\tfmt.Println(agent.IsBot())     // false\n\t// and many more...\n\n\t// Version helper functions.\n\tfmt.Println(agent.BrowserVersionMajor()) // 118\n\tfmt.Println(agent.BrowserVersionMinor()) // 0\n\tfmt.Println(agent.BrowserVersionPatch()) // 0.0\n}\n```\n\nRefer to the [pkg.go.dev](https://pkg.go.dev/github.com/medama-io/go-useragent) documentation for more details on available fields and their meanings.\n\n## Benchmarks\n\nBenchmarks were performed against [`ua-parser/uap-go`](https://github.com/ua-parser/uap-go) and [`mileusena/useragent`](https://github.com/mileusna/useragent) on an Apple M3 Pro Processor.\n\n```bash\nmise run bench\n\nMedamaParserGetSingle-12        3871813             287.2 ns/op               0 B/op          0 allocs/op\nMileusnaParserGetSingle-12      1322602             945.1 ns/op             600 B/op         16 allocs/op\nUAPParserGetSingle-12            986428              1112 ns/op             233 B/op          8 allocs/op\n\nMedamaParserGetAll-12             75219             14616 ns/op               0 B/op          0 allocs/op\nMileusnaParserGetAll-12           25644             46806 ns/op           28878 B/op        732 allocs/op\nUAPParserGetAll-12                19263             54621 ns/op           10316 B/op        352 allocs/op\n```\n\n## Acknowledgements\n\n- The library draws inspiration from the techniques outlined in this [Raygun blog post](https://raygun.com/blog/possibility-tree-fast-string-parsing/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmedama-io%2Fgo-useragent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmedama-io%2Fgo-useragent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmedama-io%2Fgo-useragent/lists"}