operatingsystem

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: LGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package operatingsystem implements the OperatingSystem parser.

Index

Constants

This section is empty.

Variables

View Source
var AndroidApps = []string{
	"com.hisense.odinbrowser",
	"com.seraphic.openinet.pre",
	"com.appssppa.idesktoppcbrowser",
	"every.browser.inc",
}

AndroidApps contains app IDs that indicate Android OS.

View Source
var ClientHintMapping = map[string][]string{
	"GNU/Linux": {"Linux"},
	"Mac":       {"MacOS"},
}

ClientHintMapping maps OS names to known client hint values. Mirrors PHP OperatingSystem::$clientHintMapping

View Source
var DesktopOsFamilies = []string{
	"AmigaOS", "IBM", "GNU/Linux", "Mac", "Unix", "Windows", "BeOS", "Chrome OS",
	"OpenVMS",
}

DesktopOsFamilies contains OS families that are known as desktop only. Mirrors PHP OperatingSystem::$desktopOsArray

View Source
var FireOsVersionMapping = map[string]string{
	"14":    "14",
	"13":    "14",
	"12":    "14",
	"11":    "8",
	"10":    "8",
	"9":     "7",
	"7":     "6",
	"5":     "5",
	"4.4.3": "4.5.1",
	"4.4.2": "4",
	"4.2.2": "3",
	"4.0.3": "3",
	"4.0.2": "3",
	"4":     "2",
	"2":     "1",
}

FireOsVersionMapping maps Android versions to Fire OS versions. Mirrors PHP OperatingSystem::$fireOsVersionMapping

View Source
var LineageOsVersionMapping = map[string]string{
	"16":    "23",
	"15":    "22",
	"14":    "21",
	"13":    "20.0",
	"12.1":  "19.1",
	"12":    "19.0",
	"11":    "18.0",
	"10":    "17.0",
	"9":     "16.0",
	"8.1.0": "15.1",
	"8.0.0": "15.0",
	"7.1.2": "14.1",
	"7.1.1": "14.1",
	"7.0":   "14.0",
	"6.0.1": "13.0",
	"6.0":   "13.0",
	"5.1.1": "12.1",
	"5.0.2": "12.0",
	"5.0":   "12.0",
	"4.4.4": "11.0",
	"4.3":   "10.2",
	"4.2.2": "10.1",
	"4.0.4": "9.1.0",
}

LineageOsVersionMapping maps Android versions to Lineage OS versions. Mirrors PHP OperatingSystem::$lineageOsVersionMapping

View Source
var OSFamilies = map[string][]string{
	"Android": {
		"AND", "CYN", "FIR", "REM", "RZD", "MLD", "MCD", "YNS", "GRI", "HAR",
		"ADR", "CLR", "BOS", "REV", "LEN", "SIR", "RRS", "WER", "PIC", "ARM",
		"HEL", "BYI", "RIS", "PUF", "LEA", "MET", "OHS", "SMA",
	},
	"AmigaOS":        {"AMG", "MOR", "ARO"},
	"BlackBerry":     {"BLB", "QNX"},
	"Brew":           {"BMP"},
	"BeOS":           {"BEO", "HAI"},
	"Chrome OS":      {"COS", "CRS", "FYD", "SEE"},
	"Firefox OS":     {"FOS", "KOS"},
	"Gaming Console": {"WII", "PS3"},
	"Google TV":      {"GTV"},
	"IBM":            {"OS2"},
	"iOS":            {"IOS", "ATV", "WAS", "IPA"},
	"RISC OS":        {"ROS"},
	"GNU/Linux": {
		"LIN", "ARL", "DEB", "KNO", "MIN", "UBT", "KBT", "XBT", "LBT", "FED",
		"RHT", "VLN", "MDR", "GNT", "SAB", "SLW", "SSE", "CES", "BTR", "SAF",
		"OSS",
		"ORD", "TOS", "RSO", "DEE", "FRE", "MAG", "FEN", "CAI", "PCL", "HAS",
		"LOS", "DVK", "ROK", "OWR", "OTV", "KTV", "PUR", "PLA", "FUC", "PAR",
		"FOR", "MON", "KAN", "ZEN", "LND", "LNS", "CHN", "AMZ", "TEN", "CST",
		"NOV", "ROU", "ZOR", "RED", "KAL", "ORA", "VID", "TIV", "BSN", "RAS",
		"UOS", "PIO", "FRI", "LIR", "WEB", "SER", "ASP", "AOS", "LOO", "EUL",
		"SCI", "ALP", "CLO", "ROC", "OVZ", "PVE", "RST", "EZX", "GNS", "JOL",
		"TUR", "QTP", "WPO", "PAN", "VIZ", "AZU", "COL",
	},
	"Mac":                   {"MAC"},
	"Mobile Gaming Console": {"PSP", "NDS", "XBX"},
	"OpenVMS":               {"OVS"},
	"Real-time OS":          {"MTK", "TDX", "MRE", "JME", "REX", "RXT", "KOL"},
	"Other Mobile":          {"WOS", "POS", "SBA", "TIZ", "SMG", "MAE", "LUN", "GEO"},
	"Symbian":               {"SYM", "SYS", "SY3", "S60", "S40"},
	"Unix": {
		"SOS", "AIX", "HPX", "BSD", "NBS", "OBS", "DFB", "SYL", "IRI", "T64",
		"INF", "ELE", "GNX", "ULT", "NWS", "NXT", "SBL",
	},
	"WebTV":          {"WTV"},
	"Windows":        {"WIN"},
	"Windows Mobile": {"WPH", "WMO", "WCE", "WRT", "WIO", "KIN"},
	"Other Smart TV": {"WHS", "TIT", "ORS"},
}

OSFamilies maps OS family names to short codes of member OSes. Mirrors PHP OperatingSystem::$osFamilies

View Source
var OperatingSystems = map[string]string{}/* 192 elements not displayed */

OperatingSystems maps short codes to full OS names. Mirrors PHP OperatingSystem::$operatingSystems

Functions

func GetAvailableOperatingSystemFamilies

func GetAvailableOperatingSystemFamilies() map[string][]string

GetAvailableOperatingSystemFamilies returns all available OS families.

func GetAvailableOperatingSystems

func GetAvailableOperatingSystems() map[string]string

GetAvailableOperatingSystems returns all available operating systems.

func GetNameFromId

func GetNameFromId(os string, ver string) string

GetNameFromId returns the full name for the given short name.

func GetOsFamily

func GetOsFamily(osLabel string) string

GetOsFamily returns the OS family for the given OS (by short name or name).

func IsDesktopOs

func IsDesktopOs(osName string) bool

IsDesktopOs returns true if the OS is desktop only.

Types

type Entry

type Entry struct {
	Regex    string    `yaml:"regex"`
	Name     string    `yaml:"name"`
	Version  string    `yaml:"version"`
	Versions []Version `yaml:"versions,omitempty"`
	// contains filtered or unexported fields
}

Entry represents a single OS definition from the YAML regex file.

func (*Entry) GetRegex

func (e *Entry) GetRegex() string

GetRegex is used for keyword extraction / indexing.

func (*Entry) Order

func (e *Entry) Order() int

Order preserves YAML order for deterministic "first match wins" selection.

type Match

type Match struct {
	Name      string `json:"name" yaml:"name"`
	ShortName string `json:"short_name" yaml:"short_name"`
	Version   string `json:"version" yaml:"version"`
	Platform  string `json:"platform" yaml:"platform"`
	Family    string `json:"family" yaml:"family"`
}

Match represents the result of a successful OS detection. This matches the PHP return structure.

type Option

type Option func(*Parser)

Option is a functional option for configuring Parser behavior.

func WithClientHints

func WithClientHints(ch *clienthints.ClientHints) Option

WithClientHints sets client hints for the parser.

type Parser

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

Parser parses a single user agent for OS information. Created via ParserFactory.NewParser() - do not instantiate directly.

func (*Parser) Parse

func (p *Parser) Parse() *Match

Parse detects the operating system and returns a Match, or nil if not detected. Mirrors PHP: DeviceDetector\Parser\OperatingSystem::parse(): ?array

type ParserFactory

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

ParserFactory holds pre-compiled regexes and creates Parser instances. Thread-safe for concurrent use - create once, use from multiple goroutines.

func NewDefaultParserFactory

func NewDefaultParserFactory(opts ...common.FactoryOption) (*ParserFactory, error)

NewDefaultParserFactory is an alias for NewParserFactory kept for compatibility.

func NewParserFactory

func NewParserFactory(opts ...common.FactoryOption) (*ParserFactory, error)

NewParserFactory creates a factory by loading and compiling regexes from the embedded YAML DB.

func (*ParserFactory) NewParser

func (f *ParserFactory) NewParser(ua string, opts ...Option) *Parser

NewParser creates a new Parser instance for parsing a single user agent.

func (*ParserFactory) Parse

func (f *ParserFactory) Parse(ua string, opts ...Option) *Match

Parse is a convenience method that creates a parser and immediately parses.

type Version

type Version struct {
	Regex   string `yaml:"regex"`
	Name    string `yaml:"name,omitempty"`
	Version string `yaml:"version"`
	// contains filtered or unexported fields
}

Version represents a sub-pattern for version detection within an OS entry.

Jump to

Keyboard shortcuts

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