fifd

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2022 License: MIT Imports: 4 Imported by: 0

README

Software License Go Report Card

Golang implementation of 51Degrees/Device-Detection based on trie without cgo.

Installation

go get github.com/IncSW/fifd

import "github.com/IncSW/fifd"

Quick Start

reader, err := fifd.NewReaderFromFile("path/to/51DegreesV3.4.trie")
if err != nil {
	panic(err)
}
device := reader.MatchDevice("UserAgent")
fmt.Println(device.GetValue("BrowserName"), device.GetValue("BrowserVersion"))

Performance

Go 1.14.2, Debian 9.1, i7-7700

fixed ua: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0

fifd/fixed-8             1291940    927 ns/op     0 B/op    0 allocs/op
cgo/fixed-8               533149   2214 ns/op   224 B/op   19 allocs/op

fifd/fixed-parallel-8    6384787    189 ns/op     0 B/op    0 allocs/op
cgo/fixed-parallel-8     2139506    554 ns/op   224 B/op   19 allocs/op

fifd/range-8              422196   2720 ns/op     0 B/op    0 allocs/op
cgo/range-8               404926   2964 ns/op   235 B/op   18 allocs/op

fifd/range-parallel-8    2738305    430 ns/op     0 B/op    0 allocs/op
cgo/range-parallel-8     1810068    657 ns/op   235 B/op   18 allocs/op

License

MIT License.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var POWERS [129]uint32 = [129]uint32{}/* 129 elements not displayed */

Functions

This section is empty.

Types

type Device

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

func (*Device) GetValue

func (d *Device) GetValue(propertyName string) string

type Matcher

type Matcher struct {
	// contains filtered or unexported fields
}

func NewMatcher

func NewMatcher(reader *Reader, userAgent string, drift int, difference int) Matcher

func (*Matcher) Match

func (m *Matcher) Match() Device

type Node

type Node struct {
	UnmatchedNodeOffset int32
	FirstIndex          int16
	LastIndex           int16
	Length              int
	HashesCount         int32
	Modulo              uint32
	Hashes              []NodeHash
}

type NodeHash

type NodeHash struct {
	HashCode   uint32
	NodeOffset int32
}

type Property

type Property struct {
	StringOffset   int
	ComponentIndex int
	SubIndex       int
}

type Reader

type Reader struct {
	BaseDrift      int
	BaseDifference int
	// contains filtered or unexported fields
}

func NewReader

func NewReader(buffer []byte) (*Reader, error)

func NewReaderFromFile

func NewReaderFromFile(filename string) (*Reader, error)

func (*Reader) MatchDevice

func (r *Reader) MatchDevice(userAgent string) Device

func (*Reader) MatchDeviceWithTolerances added in v0.0.3

func (r *Reader) MatchDeviceWithTolerances(userAgent string, drift int, difference int) Device

Directories

Path Synopsis
test

Jump to

Keyboard shortcuts

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