core

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Itoa

func Itoa(v int) string

Itoa converts an int to its decimal string representation without importing strconv.

Types

type AndroidVersion

type AndroidVersion struct {
	Version
	BuildNumber   string
	PlatformModel string
}

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

type ChromiumVersion struct {
	Version
	Webkit Version
}

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 Fixed

func Fixed(v int) IntOrRange

Fixed returns an IntOrRange with a fixed value.

func Range

func Range(min, max int) IntOrRange

Range returns an IntOrRange representing the half-open interval [min, max).

func (IntOrRange) Resolve

func (r IntOrRange) Resolve(rng *rand.Rand) int

Resolve returns the fixed Value, or a random integer in [Min, Max) using the provided random source.

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

type SafariVersion struct {
	Version
	Webkit Version
}

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

type Version struct {
	Major *int
	Minor *int
	Build *int
	Patch *int
}

Version is a resolved version with up to four components. Nil fields indicate components that are not set.

func NewVersion

func NewVersion(major int, parts ...int) Version

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) Equal

func (v Version) Equal(other Version) bool

Equal reports whether v and other represent the same version.

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) Greater

func (v Version) Greater(other Version) bool

Greater reports whether v is strictly greater than other.

func (Version) GreaterOrEqual

func (v Version) GreaterOrEqual(other Version) bool

GreaterOrEqual reports whether v is greater than or equal to other.

func (Version) Less

func (v Version) Less(other Version) bool

Less reports whether v is strictly less than other using lexicographic comparison of (major, minor, build, patch).

func (Version) LessOrEqual

func (v Version) LessOrEqual(other Version) bool

LessOrEqual reports whether v is less than or equal to other.

func (Version) String

func (v Version) String() string

String returns the default formatted version string.

func (Version) Tuple

func (v Version) Tuple() [4]int

Tuple returns a fixed-size array [major, minor, build, patch] where nil components are represented as 0.

type VersionRange

type VersionRange struct {
	MinVersion *Version
	MaxVersion *Version
}

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.

func (VersionSpec) Resolve

func (vs VersionSpec) Resolve(rng *rand.Rand) Version

Resolve converts a VersionSpec into a concrete Version by resolving each non-nil field using the provided random source.

type WindowsVersion

type WindowsVersion struct {
	Version
	CHPlatform Version
}

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.

Jump to

Keyboard shortcuts

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