Documentation
¶
Index ¶
- func Itoa(v int) string
- type AndroidVersion
- type AndroidVersionSpec
- type ChromiumVersion
- type ChromiumVersionSpec
- type FormatOption
- type GeneratorData
- type IntOrRange
- type Options
- type SafariVersion
- type SafariVersionSpec
- type Version
- func (v Version) Equal(other Version) bool
- func (v Version) Format(opts ...FormatOption) string
- func (v Version) Greater(other Version) bool
- func (v Version) GreaterOrEqual(other Version) bool
- func (v Version) Less(other Version) bool
- func (v Version) LessOrEqual(other Version) bool
- func (v Version) String() string
- func (v Version) Tuple() [4]int
- type VersionRange
- type VersionSpec
- type WindowsVersion
- type WindowsVersionSpec
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AndroidVersion ¶
AndroidVersion is a resolved Android platform version with an optional build number and platform model string.
type AndroidVersionSpec ¶
type AndroidVersionSpec struct {
Spec VersionSpec
BuildNumbers []string
}
AndroidVersionSpec is a template for generating random AndroidVersion values. Resolution of Android versions is handled by the platform package because it involves build number template expansion and model selection.
type ChromiumVersion ¶
ChromiumVersion is a resolved Chromium-based browser version that includes both the browser version and the WebKit version.
type ChromiumVersionSpec ¶
type ChromiumVersionSpec struct {
Spec VersionSpec
Webkit VersionSpec
}
ChromiumVersionSpec is a template for generating random ChromiumVersion values.
func (ChromiumVersionSpec) Resolve ¶
func (s ChromiumVersionSpec) Resolve(rng *rand.Rand) ChromiumVersion
Resolve generates a concrete ChromiumVersion by resolving both the browser and WebKit version specs.
type FormatOption ¶
type FormatOption func(*formatConfig)
FormatOption is a functional option for Version.Format.
func WithLimit ¶
func WithLimit(n int) FormatOption
WithLimit zeroes any version components at indices >= n.
func WithPartitions ¶
func WithPartitions(n int) FormatOption
WithPartitions limits the output to at most n version components.
func WithSeparator ¶
func WithSeparator(s string) FormatOption
WithSeparator sets the string used to join version components. The default is ".".
func WithTrimZero ¶
func WithTrimZero() FormatOption
WithTrimZero removes trailing zero components from the formatted output.
type GeneratorData ¶
type GeneratorData struct {
Device string
Platform string
Browser string
UserAgent string
PlatformVersion Version
BrowserVersion Version
WindowsVer *WindowsVersion
AndroidVer *AndroidVersion
}
GeneratorData holds the subset of generator fields needed by ClientHints. It is populated by the internal/data package and passed into NewClientHints to provide version and platform information.
type IntOrRange ¶
type IntOrRange struct {
Value int
IsRange bool
Min int // inclusive
Max int // exclusive, used with rng.IntN
}
IntOrRange represents either a fixed integer value or a half-open range [Min, Max) from which a random value is generated.
func Range ¶
func Range(min, max int) IntOrRange
Range returns an IntOrRange representing the half-open interval [min, max).
type Options ¶
type Options struct {
// WeightedVersions increases the probability of the latest versions being chosen.
WeightedVersions bool
// VersionRanges constrains version selection by browser or platform name.
// Keys are browser names ("chrome", "edge", "firefox", "safari") or
// platform names ("windows", "macos", "ios", "linux", "android").
VersionRanges map[string]VersionRange
// TiedSafariVersion makes Safari version tied to the macOS/iOS platform version.
TiedSafariVersion bool
}
Options configures user-agent generation behavior.
type SafariVersion ¶
SafariVersion is a resolved Safari browser version that includes both the browser version and the WebKit version.
type SafariVersionSpec ¶
type SafariVersionSpec struct {
Spec VersionSpec
Webkit VersionSpec
}
SafariVersionSpec is a template for generating random SafariVersion values.
func (SafariVersionSpec) Resolve ¶
func (s SafariVersionSpec) Resolve(rng *rand.Rand) SafariVersion
Resolve generates a concrete SafariVersion by resolving both the browser and WebKit version specs.
type Version ¶
Version is a resolved version with up to four components. Nil fields indicate components that are not set.
func NewVersion ¶
NewVersion creates a Version from positional integer arguments. The first argument sets Major; subsequent arguments set Minor, Build, and Patch in order. For example: NewVersion(10, 5, 3) sets Major=10, Minor=5, Build=3.
func (Version) Format ¶
func (v Version) Format(opts ...FormatOption) string
Format returns a string representation of the version. Options control the number of partitions, field limit, separator, and whether trailing zeros are trimmed. With no options, all non-nil components are joined with ".".
func (Version) GreaterOrEqual ¶
GreaterOrEqual reports whether v is greater than or equal to other.
func (Version) Less ¶
Less reports whether v is strictly less than other using lexicographic comparison of (major, minor, build, patch).
func (Version) LessOrEqual ¶
LessOrEqual reports whether v is less than or equal to other.
type VersionRange ¶
VersionRange constrains version filtering by optional minimum and maximum major version bounds.
func NewVersionRange ¶
func NewVersionRange(min, max int) VersionRange
NewVersionRange creates a VersionRange from major version integers. A value of 0 means no bound (nil).
func (VersionRange) Filter ¶
func (vr VersionRange) Filter(versions []VersionSpec) []VersionSpec
Filter returns a subset of the provided VersionSpec slice that falls within the range. Filtering is based on the major version component only.
type VersionSpec ¶
type VersionSpec struct {
Major *IntOrRange
Minor *IntOrRange
Build *IntOrRange
Patch *IntOrRange
}
VersionSpec is a template for a version before random resolution. Nil fields indicate components that are not set.
type WindowsVersion ¶
WindowsVersion is a resolved Windows platform version that includes a Client Hints platform version.
type WindowsVersionSpec ¶
type WindowsVersionSpec struct {
Spec VersionSpec
CHPlatform VersionSpec
}
WindowsVersionSpec is a template for generating random WindowsVersion values.
func (WindowsVersionSpec) Resolve ¶
func (s WindowsVersionSpec) Resolve(rng *rand.Rand) WindowsVersion
Resolve generates a concrete WindowsVersion by resolving both the OS version and the Client Hints platform version specs.