Skip to content

User Agents detector for tv, phone, tablet and desktop devices.

License

Notifications You must be signed in to change notification settings

emetriq/gouseragents

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Coverage Status RELEASE CI

gouseragents

Accurate and fresh list of desktop, phone, tablet and tv user agents.

install

go get github.com/emetriq/gouseragents

usage

import (
   "fmt"
   "github.com/emetriq/gouseragents/desktop"
   "github.com/emetriq/gouseragents/tv"
   "github.com/emetriq/gouseragents/phone"
   "github.com/emetriq/gouseragents/tablet"
)

func main() {
   if desktop.IsDesktopUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:97.0) Gecko/20100101 Firefox/97.0") {
      fmt.Println("Desktop user agent")
   }

   if tv.IsTVUserAgent("Dalvik/2.1.0 (Linux; U; Android 9; AFTSSS Build/PS7242) CTV") {
      fmt.Println("TV user agent")
   }

   if phone.IsPhoneUserAgent("samsung SM-A515F Android 11 phone") {
      fmt.Println("Phone user agent")
   }

   if tablet.IsTabletUserAgent("samsung SM-T585 Android 8.1.0 tablet") {
      fmt.Println("Tablet user agent")
   }
}

update useragents

The code base are json files located in the "gen" directory. After a file change you have to start the code generator with go generate gen/useragents.go. Create a PR. Done.