udger

package module
v0.0.0-...-c930e9a Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2019 License: MIT Imports: 5 Imported by: 0

README

Udger golang (format V3):

This package is a fork of github.com/udger/udger with the following changes:

  • Using golang regexp instead of github.com/glenn-brown/golang-pkg-pcre
  • Supporting partial UA parsing by constructor flags (device, browser, os)

Usage:

package main

import (
  "github.com/yoavfeld/udger"
)

func main() {
  client, err := udger.New("udgerDBv3FilePath", &udger.Flags{Device: true})
  if err != nil {
     log.Fatal(err)
  }
  ua := "Mozilla/5.0 (Linux; Android 4.4.4; MI PAD Build/KTU84P) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/33.0.0.0 Safari/537.36"
  res,err := client.Lookup(ua)
  if err != nil {
    log.Fatal(err)
  }
}


Open issues:

  • Browser version is not supported since using golang regexp. it require a fix in findData func to support findDataWithVersion func

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

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 it's name

type Device

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

Device contains all the information about the Device type

type Flags

type Flags struct {
	Device bool
	// contains filtered or unexported fields
}

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
	Flags    *Flags
	// contains filtered or unexported fields
}

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

func New

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

New creates a new instance of Udger and load all the database in memory to allow fast lookup you need to pass the sqlite database in parameter

func (*Udger) Lookup

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

Lookup one user agent and return a Info struct who contains all the metadata possible for the UA.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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