uaparser

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

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

Go to latest
Published: May 26, 2019 License: MIT Imports: 5 Imported by: 2

README

User Agent Parser For TeaWeb

More faster than other implementations.

Usage

p, err := uaparser.NewParser("/path/to/regexes.yaml")
if err != nil {
    log.Println(err.Error())
    return
}

agent, found := p.Parse("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.59 Safari/537.36")

if found {
    log.Printf("%#v,\n %#v, \n %#v", agent.Browser, agent.OS, agent.Device)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Browser

type Browser struct {
	Family string `json:"family"`
	Major  string `json:"major"`
	Minor  string `json:"minor"`
	Patch  string `json:"patch"`
}

func (*Browser) Parse

func (this *Browser) Parse(matches []string, spec map[string]string)

type Device

type Device struct {
	Family string `json:"family"`
	Brand  string `json:"brand"`
	Model  string `json:"model"`
}

func (*Device) Parse

func (this *Device) Parse(matches []string, spec map[string]string)

type OS

type OS struct {
	Family     string `json:"family"`
	Major      string `json:"major"`
	Minor      string `json:"minor"`
	Patch      string `json:"patch"`
	PatchMinor string `json:"patchMinor"`
}

func (*OS) Parse

func (this *OS) Parse(matches []string, spec map[string]string)

type Parser

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

func NewParser

func NewParser(path string) (*Parser, error)

func (*Parser) Parse

func (this *Parser) Parse(userAgentString string) (userAgent *UserAgent, found bool)

func (*Parser) ParseBrowser

func (this *Parser) ParseBrowser(userAgentString string) (browser *Browser, found bool)

func (*Parser) ParseDevice

func (this *Parser) ParseDevice(userAgentString string) (device *Device, found bool)

func (*Parser) ParseOS

func (this *Parser) ParseOS(userAgentString string) (os *OS, found bool)

type UserAgent

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

Jump to

Keyboard shortcuts

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