agency

package module
v0.0.0-...-33de8fb Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2017 License: MIT Imports: 14 Imported by: 0

README

Agency

Agency is a fast user-agent parser in pure Go. It uses a simple tokenizer and weighted tokens to determine the correct device type, category and browser.

Usage

To use Agency, simply import the package and call Scan():

import "github.com/benbjohnson/agency"

ua := agency.Scan("Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 blah blah...")

User Agent Info

The Scan() function returns a UserAgent with the following string properties:

Type
----------
Desktop
Tablet
Mobile

Category
----------
Windows
Mac
Linux
iOS
Blackberry
Android

Browser
----------
Chrome
Safari
Internet Explorer

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Asset

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDir

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.

func AssetInfo

func AssetInfo(name string) (os.FileInfo, error)

AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetNames

func AssetNames() []string

AssetNames returns the names of the assets.

func MustAsset

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.

func RestoreAsset

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory

func RestoreAssets

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively

Types

type Scanner

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

Scanner is a user agent tokenizer.

func NewScanner

func NewScanner() *Scanner

NewScanner creates a new user agent scanner.

func (*Scanner) Scan

func (s *Scanner) Scan(str string) (*UserAgent, error)

Scan scans a user agent string for device information.

func (*Scanner) ScanBytes

func (s *Scanner) ScanBytes(b []byte) (*UserAgent, error)

ScanBytes scans a user agent byte slice for device information.

type UserAgent

type UserAgent struct {
	Browser struct {
		Type string
		Name string
	}
	Device struct {
		Type string
	}
	OS struct {
		Name    string
		Version string
	}
}

UserAgent represents the results from a call to Scan().

func Scan

func Scan(str string) (*UserAgent, error)

Scan extracts properties from a user agent string.

func ScanBytes

func ScanBytes(b []byte) (*UserAgent, error)

ScanBytes extracts properties from a user agent byte slice.

Jump to

Keyboard shortcuts

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