client

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2026 License: LGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package client ports the matomo/device-detector client parsers (Parser/Client/*) to Go: browsers, feed readers, libraries, media players, mobile apps and PIMs. It implements the pure user-agent detection path; client-hints handling is out of scope for v0.1.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BrowserFamily

func BrowserFamily(browserLabel string) (string, bool)

BrowserFamily mirrors Browser::getBrowserFamily(): it accepts either a short code or a full browser name and returns the family it belongs to.

func IsMobileOnlyBrowser

func IsMobileOnlyBrowser(browser string) bool

IsMobileOnlyBrowser mirrors Browser::isMobileOnlyBrowser(): it accepts either a short code or a full browser name.

Types

type Browser

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

Browser ports Parser/Client/Browser.php: it detects browsers together with their rendering engine and engine version.

func NewBrowser

func NewBrowser(fsys fs.FS) (*Browser, error)

NewBrowser loads the browser database (and the engine database it depends on) from fsys.

func (*Browser) Name

func (b *Browser) Name() string

Name returns the parser name.

func (*Browser) Parse

func (b *Browser) Parse(ua string, hints *parser.ClientHints) (*Result, error)

Parse mirrors Browser::parse() on the pure user-agent path.

func (*Browser) SetVersionTruncation

func (b *Browser) SetVersionTruncation(t int)

SetVersionTruncation sets the version truncation level.

func (*Browser) Warm

func (b *Browser) Warm() error

Warm compiles every browser entry regex and the engine regexes.

type Engine

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

Engine ports Parser/Client/Browser/Engine.php: it detects a browser engine from the user agent using the browser_engine.yml regexes.

func NewEngine

func NewEngine(fsys fs.FS) (*Engine, error)

NewEngine loads the browser engine database from fsys.

type FeedReader

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

FeedReader detects feed readers (Parser/Client/FeedReader.php).

func NewFeedReader

func NewFeedReader(fsys fs.FS) (*FeedReader, error)

NewFeedReader loads the feed reader database from fsys.

func (FeedReader) Name

func (p FeedReader) Name() string

Name returns the parser name.

func (FeedReader) Parse

func (p FeedReader) Parse(ua string, _ *parser.ClientHints) (*Result, error)

Parse mirrors AbstractClientParser::parse().

func (FeedReader) SetVersionTruncation

func (p FeedReader) SetVersionTruncation(t int)

SetVersionTruncation sets the version truncation level.

func (FeedReader) Warm

func (p FeedReader) Warm() error

Warm compiles every entry regex.

type Library

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

Library detects tools and software libraries (Parser/Client/Library.php).

func NewLibrary

func NewLibrary(fsys fs.FS) (*Library, error)

NewLibrary loads the library database from fsys.

func (Library) Name

func (p Library) Name() string

Name returns the parser name.

func (Library) Parse

func (p Library) Parse(ua string, _ *parser.ClientHints) (*Result, error)

Parse mirrors AbstractClientParser::parse().

func (Library) SetVersionTruncation

func (p Library) SetVersionTruncation(t int)

SetVersionTruncation sets the version truncation level.

func (Library) Warm

func (p Library) Warm() error

Warm compiles every entry regex.

type MediaPlayer

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

MediaPlayer detects media players (Parser/Client/MediaPlayer.php).

func NewMediaPlayer

func NewMediaPlayer(fsys fs.FS) (*MediaPlayer, error)

NewMediaPlayer loads the media player database from fsys.

func (MediaPlayer) Name

func (p MediaPlayer) Name() string

Name returns the parser name.

func (MediaPlayer) Parse

func (p MediaPlayer) Parse(ua string, _ *parser.ClientHints) (*Result, error)

Parse mirrors AbstractClientParser::parse().

func (MediaPlayer) SetVersionTruncation

func (p MediaPlayer) SetVersionTruncation(t int)

SetVersionTruncation sets the version truncation level.

func (MediaPlayer) Warm

func (p MediaPlayer) Warm() error

Warm compiles every entry regex.

type MobileApp

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

MobileApp detects mobile applications (Parser/Client/MobileApp.php), augmenting the user-agent result with the client-hints app id (AppHints).

func NewMobileApp

func NewMobileApp(fsys fs.FS) (*MobileApp, error)

NewMobileApp loads the mobile app database from fsys.

func (MobileApp) Name

func (p MobileApp) Name() string

Name returns the parser name.

func (*MobileApp) Parse

func (m *MobileApp) Parse(ua string, hints *parser.ClientHints) (*Result, error)

Parse mirrors MobileApp::parse: the generic user-agent result refined by the client-hints app id.

func (MobileApp) SetVersionTruncation

func (p MobileApp) SetVersionTruncation(t int)

SetVersionTruncation sets the version truncation level.

func (MobileApp) Warm

func (p MobileApp) Warm() error

Warm compiles every entry regex.

type PIM

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

PIM detects personal information managers (Parser/Client/PIM.php).

func NewPIM

func NewPIM(fsys fs.FS) (*PIM, error)

NewPIM loads the PIM database from fsys.

func (PIM) Name

func (p PIM) Name() string

Name returns the parser name.

func (PIM) Parse

func (p PIM) Parse(ua string, _ *parser.ClientHints) (*Result, error)

Parse mirrors AbstractClientParser::parse().

func (PIM) SetVersionTruncation

func (p PIM) SetVersionTruncation(t int)

SetVersionTruncation sets the version truncation level.

func (PIM) Warm

func (p PIM) Warm() error

Warm compiles every entry regex.

type Parser

type Parser interface {
	// Parse returns the detected client, or nil,nil when the user agent does
	// not match this parser.
	Parse(ua string, hints *parser.ClientHints) (*Result, error)
	// Name returns the parser name as used in PHP ($parserName).
	Name() string
	// SetVersionTruncation controls how deep versions are reported. It must be
	// called before the parser is used concurrently.
	SetVersionTruncation(t int)
	// Warm eagerly compiles every regex the parser owns so a broken pattern
	// surfaces at construction rather than at first match.
	Warm() error
}

Parser is the common interface implemented by every client parser.

func All

func All(fsys fs.FS) ([]Parser, error)

All returns the client parsers in the exact order DeviceDetector.php tries them (DeviceDetector::$clientParsers): FeedReader, MobileApp, MediaPlayer, PIM, Browser, Library.

type Result

type Result struct {
	Type          string // "browser", "feed reader", "library", "mediaplayer", "mobile app", "pim"
	Name          string
	Version       string
	Engine        string // browser only
	EngineVersion string // browser only
	Family        string // browser only
	ShortName     string // browser only (internal short code)
}

Result holds a detected client. Engine, EngineVersion, Family and ShortName are only populated for the browser parser.

Jump to

Keyboard shortcuts

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