useragent

package
v0.0.0-...-8aeb8a1 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const ParsedUaKey = "parsed_ua"

ParsedUaKey is a json key for parsed user-agent data object

Variables

View Source
var BotUAKeywords = []string{"bot", "spider", "headless", "crawler", "uptimia"}

Functions

This section is empty.

Types

type Mock

type Mock struct{}

Mock it is used for returning mocked user-agent object instead of resolving

func (Mock) Resolve

func (Mock) Resolve(ua string) *ResolvedUa

Resolve returns mocked prased user-agent object

type ResolvedUa

type ResolvedUa struct {
	UaFamily  string `mapstructure:"ua_family,omitempty" json:"ua_family,omitempty"`
	UaVersion string `mapstructure:"ua_version,omitempty" json:"ua_version,omitempty"`

	OsFamily  string `mapstructure:"os_family,omitempty" json:"os_family,omitempty"`
	OsVersion string `mapstructure:"os_version,omitempty" json:"os_version,omitempty"`

	DeviceFamily string `mapstructure:"device_family,omitempty" json:"device_family,omitempty"`
	DeviceBrand  string `mapstructure:"device_brand,omitempty" json:"device_brand,omitempty"`
	DeviceModel  string `mapstructure:"device_model,omitempty" json:"device_model,omitempty"`

	Bot bool `mapstructure:"bot,omitempty" json:"bot,omitempty"`
}

ResolvedUa model for keeping resolved user-agent data

func (ResolvedUa) IsEmpty

func (rua ResolvedUa) IsEmpty() bool

IsEmpty returns true if all values in ResolvedUa is empty

type Resolver

type Resolver interface {
	Resolve(ua string) *ResolvedUa
}

Resolver performs user-agent string parsing into ResolvedUa struct can be mocked

func NewResolver

func NewResolver(extraBotUaKeywords []string) Resolver

NewResolver returns new instance of UaResolver

type UaResolver

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

UaResolver parses user-agent strings into ResolvedUa structures with "github.com/ua-parser/uap-go/uaparser"

func (*UaResolver) Resolve

func (r *UaResolver) Resolve(ua string) *ResolvedUa

Resolve client user-agent with github.com/ua-parser/uap-go/uaparser lib Return nil if parsed ua is empty

Jump to

Keyboard shortcuts

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