uaxpl

package module
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: MIT Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

UserAgent eXPLain library.

Go port of device-detector library. Designed to use in high-load.

Library doesn't provide 100% match with original PHP library due to different Regexp engine (Go regexp vs PHP PCRE). Difference is ~ 5%.

Usage
ctx := uaxpl.Acquire()
defer uaxpl.Release(ctx)
ctx.SetUserAgentStr("Mozilla/5.0 (Linux; U; Android 9; RMX1941 Build/PPR1.180610.011) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/53.0.2785.134 Mobile Safari/537.36 RealmeBrowser/35.5.0.8")
fmt.Println("client type:", ctx.GetClientType())               // browser
fmt.Println("browser:", ctx.GetBrowser())                      // Realme Browser
fmt.Println("browser version:", ctx.GetBrowserVersionString()) // 35.5.0.8
fmt.Println("browser version full:", ctx.GetBrowserVersion())  // 35.5.0.8
fmt.Println("engine:", ctx.GetEngine())                        // WebKit
fmt.Println("engine version:", ctx.GetEngineVersionString())   // 537.36
fmt.Println("engine version full:", ctx.GetEngineVersion())    // 537.36.0.0
fmt.Println("device type:", ctx.GetDeviceType())               // smartphone
fmt.Println("brand:", ctx.GetBrand())                          // Realme
fmt.Println("model:", ctx.GetModel())                          // C2
fmt.Println("OS:", ctx.GetOS())                                // Android
fmt.Println("OS version:", ctx.GetOSVersionString())           // 9
fmt.Println("OS version full:", ctx.GetOSVersion())            // 9.0.0.0
CLI Installation

uaxpl has two cli commands: uaxpl and uaxplc. First on is a simple cli tool to parse UA in terminals.

uaxplc uses to recompile internal repositories from device-detector's YAML files.

To install the tool run

go install github.com/koykov/uaxpl/cmd/uaxplc

As result, you must have binary $GOPATH/bin/uaxplc.

Then recompile the repos

go get github.com/koykov/uaxpl
cd $GOPATH/src/github.com/koykov/uaxpl
go generate

Run tests to make sure repos were compiled successfully.

Documentation

Index

Constants

View Source
const (
	Unknown = "UNK"
)

Variables

This section is empty.

Functions

func Release

func Release(ctx *Ctx)

Release puts context back to default pool instance.

Types

type ClientType

type ClientType uint8
const (
	ClientTypeBrowser ClientType = 1 << iota
	ClientTypeMobileApp
	ClientTypeLibrary
	ClientTypeFeedReader
	ClientTypeMediaPlayer
	ClientTypePIM
	ClientTypeAll = ClientTypeBrowser | ClientTypeMobileApp | ClientTypeLibrary | ClientTypeFeedReader |
		ClientTypeMediaPlayer | ClientTypePIM
)

func (ClientType) String

func (t ClientType) String() string

type Ctx

type Ctx struct {
	bitset.Bitset
	// contains filtered or unexported fields
}

func Acquire

func Acquire() *Ctx

Acquire gets context from default pool instance.

func AcquireWithSrc

func AcquireWithSrc(src []byte) *Ctx

func AcquireWithSrcStr

func AcquireWithSrcStr(src string) *Ctx

func NewCtx

func NewCtx() *Ctx

func NewCtxWithSrc

func NewCtxWithSrc(src []byte) *Ctx

func NewCtxWithSrcStr

func NewCtxWithSrcStr(src string) *Ctx

func (*Ctx) FilterClientType

func (c *Ctx) FilterClientType(mask ClientType) *Ctx

func (*Ctx) FilterDeviceType

func (c *Ctx) FilterDeviceType(mask DeviceType) *Ctx

func (*Ctx) GetBrand

func (c *Ctx) GetBrand() string

func (*Ctx) GetBrowser

func (c *Ctx) GetBrowser() string

func (*Ctx) GetBrowserVersion

func (c *Ctx) GetBrowserVersion() *Version

func (*Ctx) GetBrowserVersionString

func (c *Ctx) GetBrowserVersionString() string

func (*Ctx) GetClientType

func (c *Ctx) GetClientType() ClientType

func (*Ctx) GetDeviceType

func (c *Ctx) GetDeviceType() DeviceType

func (*Ctx) GetEngine

func (c *Ctx) GetEngine() string

func (*Ctx) GetEngineVersion

func (c *Ctx) GetEngineVersion() *Version

func (*Ctx) GetEngineVersionString

func (c *Ctx) GetEngineVersionString() string

func (*Ctx) GetModel

func (c *Ctx) GetModel() string

func (*Ctx) GetOS

func (c *Ctx) GetOS() string

func (*Ctx) GetOSVersion

func (c *Ctx) GetOSVersion() *Version

func (*Ctx) GetOSVersionString

func (c *Ctx) GetOSVersionString() string

func (*Ctx) GetUserAgent

func (c *Ctx) GetUserAgent() string

func (*Ctx) Reset

func (c *Ctx) Reset()

func (*Ctx) SetRequestedWith

func (c *Ctx) SetRequestedWith(header string) *Ctx

func (*Ctx) SetUserAgent

func (c *Ctx) SetUserAgent(src []byte) *Ctx

func (*Ctx) SetUserAgentStr

func (c *Ctx) SetUserAgentStr(src string) *Ctx

type DeviceType

type DeviceType uint16
const (
	DeviceTypeNotebook DeviceType = 1 << iota
	DeviceTypeMobile
	DeviceTypePhablet
	DeviceTypeTablet
	DeviceTypeConsole
	DeviceTypeTV
	DeviceTypeShellTV
	DeviceTypeCamera
	DeviceTypeCarBrowser
	DeviceTypePortableMediaPlayer
	DeviceTypeAll = DeviceTypeTV | DeviceTypeShellTV | DeviceTypeNotebook | DeviceTypeConsole |
		DeviceTypeCarBrowser | DeviceTypeCamera | DeviceTypePortableMediaPlayer | DeviceTypeMobile | DeviceTypePhablet |
		DeviceTypeTablet
)

func (DeviceType) String

func (t DeviceType) String() string

type Pool

type Pool struct {
	// contains filtered or unexported fields
}
var (
	// P is a default instance of the pool.
	// Just call uaxpl.Acquire() and uaxpl.Release().
	P Pool
)

func (*Pool) Get

func (p *Pool) Get() *Ctx

Get old context from the pool or create new one.

func (*Pool) Put

func (p *Pool) Put(ctx *Ctx)

Put context back to the pool.

type Version

type Version struct {
	Major    int32
	Minor    int32
	Patch    int32
	Revision int32
	Suffix   string
	// contains filtered or unexported fields
}

func (*Version) Parse

func (v *Version) Parse(s string) error

func (*Version) Reset

func (v *Version) Reset()

func (Version) String

func (v Version) String() string

func (Version) Write

func (v Version) Write(dst []byte) []byte

Directories

Path Synopsis
cmd
uaxpl command
uaxplc module

Jump to

Keyboard shortcuts

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