Documentation
¶
Overview ¶
Package platform holds the OS/arch knowledge that used to be duplicated across install, install/detect, client and app/cache: alias/token tables and the recognition regex tables.
It holds data and splitting primitives only. The "does this name belong to this platform" decisions stay with their call sites (nameHasPlatform, trimPlatformSuffix, systemDetector.Detect), so the tables can be shared without changing any behaviour — see docs/plans/2026-10-17-rule-consolidation-plan.md.
Index ¶
- Variables
- func Aliases(goos, goarch string) ([]string, []string)
- func ArchTokens() []string
- func DirArchPatterns(goarch string) []*regexp.Regexp
- func HasAnyToken(tokens []string, aliases ...string) bool
- func OSTokens() []string
- func SplitTokens(name string) []string
- func TrimPlatformSuffixRegexps() []*regexp.Regexp
- func VariantTokens() []string
- type ArchSpec
- type OSSpec
Constants ¶
This section is empty.
Variables ¶
var DetectArchSpecs = []ArchSpec{ {Name: "amd64", Regex: regexp.MustCompile(`(?i)(x64|amd64|x86(-|_)?64)`)}, {Name: "386", Regex: regexp.MustCompile(`(?i)(x32|amd32|x86(-|_)?32|i?386)`)}, {Name: "arm", Regex: regexp.MustCompile(`(?i)(arm32|armv6|arm\b)`)}, {Name: "arm64", Regex: regexp.MustCompile(`(?i)(arm64|armv8|aarch64)`)}, {Name: "riscv64", Regex: regexp.MustCompile(`(?i)(riscv64)`)}, }
DetectArchSpecs is the architecture recognition table of install/detect.
var DetectOSSpecs = []OSSpec{ {Name: "darwin", Regex: regexp.MustCompile(`(?i)(darwin|mac.?(os)?|osx)`)}, {Name: "windows", Regex: regexp.MustCompile(`(?i)([^r]win|windows|\.exe$|\.msi$)`), Priority: regexp.MustCompile(`(?i)\.exe$`)}, {Name: "linux", Regex: regexp.MustCompile(`(?i)(linux|ubuntu)`), Anti: regexp.MustCompile(`(?i)(android)`), Priority: regexp.MustCompile(`\.appimage$`)}, {Name: "netbsd", Regex: regexp.MustCompile(`(?i)(netbsd)`)}, {Name: "freebsd", Regex: regexp.MustCompile(`(?i)(freebsd)`)}, {Name: "openbsd", Regex: regexp.MustCompile(`(?i)(openbsd)`)}, {Name: "android", Regex: regexp.MustCompile(`(?i)(android)`)}, {Name: "illumos", Regex: regexp.MustCompile(`(?i)(illumos)`)}, {Name: "solaris", Regex: regexp.MustCompile(`(?i)(solaris)`)}, {Name: "plan9", Regex: regexp.MustCompile(`(?i)(plan9)`)}, }
DetectOSSpecs is the OS recognition table of install/detect. The regexes are kept verbatim from the original table.
var GOARCHSpecIndex = indexArchSpecs()
GOARCHSpecIndex indexes DetectArchSpecs by name.
var GOOSSpecIndex = indexOSSpecs()
GOOSSpecIndex indexes DetectOSSpecs by name; the key set is the authoritative "known GOOS" set.
Functions ¶
func ArchTokens ¶
func ArchTokens() []string
ArchTokens returns the architecture tokens recognised in file names. The returned slice is owned by this package: callers must not modify it.
func DirArchPatterns ¶
DirArchPatterns returns the patterns that match an extracted directory or file path belonging to goarch (install.autoSelectExtractedFile). It returns nil for architectures without a dedicated pattern.
func HasAnyToken ¶
HasAnyToken reports whether tokens contains one of aliases.
func OSTokens ¶
func OSTokens() []string
OSTokens returns the OS tokens recognised in file names. The returned slice is owned by this package: callers must not modify it.
func SplitTokens ¶
SplitTokens splits a name into tokens using both the "-./\\" and the "-_. /\\" separator sets, after lower-casing and normalising slashes.
func TrimPlatformSuffixRegexps ¶
TrimPlatformSuffixRegexps returns the three patterns that strip an OS/arch (or bare OS) suffix from an executable name, as used by install.heuristicExecutableName.
The table is deliberately kept verbatim: "armv?6"/"armv?7" express an optional "v", and the patterns also encode the os-arch order, the separators and the end anchor, none of which can be derived from the token lists.
func VariantTokens ¶
func VariantTokens() []string
VariantTokens returns the executable variant tokens (e.g. "portable").
Types ¶
type OSSpec ¶
OSSpec is the recognition data for one operating system. Regex is the match pattern, Anti a pattern that disqualifies a match (e.g. android for linux) and Priority a pattern that makes the OS a preferred match. Nil means "absent" and carries no meaning by itself: how anti/priority are applied stays with the detector.