udger

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2023 License: MIT Imports: 5 Imported by: 0

README

Udger Golang

This package reads in memory all the database from Udger and lets you lookup for user agent's metadata. The parsing only relies on the golang standard library regex. Only the Udger Data v3 - Sqlite3 format is supported.

This package is a fork of https://github.com/yoavfeld/udger itself forked from https://github.com/udger/udger.

Tests / Benchmarks

To run tests and benchmarks you need to have the Udger database udgerdb_v3.dat located in this folder.

To run unit tests and run:

go tests ./...

To run tests with benchmarks:

go test -bench=.

Documentation

Overview

Package udger package allow you to load in memory and lookup the user agent database to extract value from the provided user agent

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Browser

type Browser struct {
	Name    string `json:"name"`
	Family  string `json:"family"`
	Version string `json:"version"`
	Engine  string `json:"engine"`

	Type    string `json:"type"`
	Company string `json:"company"`
	Icon    string `json:"icon"`
	// contains filtered or unexported fields
}

Browser contains information about the browser type, engine and off course its name

type Device

type Device struct {
	Name string `json:"name"`
	Icon string `json:"icon"`
}

Device contains all the information about the Device type

type Info

type Info struct {
	Browser Browser `json:"browser"`
	OS      OS      `json:"os"`
	Device  Device  `json:"device"`
}

Info is the struct returned by the Lookup(ua string) function, contains everything about the UA

type OS

type OS struct {
	Name    string `json:"name"`
	Family  string `json:"family"`
	Icon    string `json:"icon"`
	Company string `json:"company"`
}

OS contains all the information about the operating system

type Udger

type Udger struct {
	Browsers map[int]Browser
	OS       map[int]OS
	Devices  map[int]Device
	// contains filtered or unexported fields
}

Udger contains the data and exposes the Lookup(ua string) function

func New

func New(dbPath string) (*Udger, error)

New creates a new instance of Udger from the dbPath database loaded in memory for fast lookup.

func (*Udger) Lookup

func (udger *Udger) Lookup(ua string) (*Info, error)

Lookup returns all the metadata possible for the given user agent string ua.

Example
udger, err := New("./udgerdb_v3.dat")
if err != nil {
	panic(err)
}

info, err := udger.Lookup("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2575.0 Safari/537.36")
if err != nil {
	panic(err)
}
fmt.Println(info.Browser.Family, info.OS.Family)
Output:

Chrome OS X

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL