platform

package
v1.15.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 3 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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.

View Source
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.

View Source
var GOARCHSpecIndex = indexArchSpecs()

GOARCHSpecIndex indexes DetectArchSpecs by name.

View Source
var GOOSSpecIndex = indexOSSpecs()

GOOSSpecIndex indexes DetectOSSpecs by name; the key set is the authoritative "known GOOS" set.

Functions

func Aliases

func Aliases(goos, goarch string) ([]string, []string)

Aliases expands a goos/goarch pair into the file-name aliases that identify it.

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

func DirArchPatterns(goarch string) []*regexp.Regexp

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

func HasAnyToken(tokens []string, aliases ...string) bool

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

func SplitTokens(name string) []string

SplitTokens splits a name into tokens using both the "-./\\" and the "-_. /\\" separator sets, after lower-casing and normalising slashes.

func TrimPlatformSuffixRegexps

func TrimPlatformSuffixRegexps() []*regexp.Regexp

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 ArchSpec

type ArchSpec struct {
	Name  string
	Regex *regexp.Regexp
}

ArchSpec is the recognition data for one architecture.

type OSSpec

type OSSpec struct {
	Name     string
	Regex    *regexp.Regexp
	Anti     *regexp.Regexp
	Priority *regexp.Regexp
}

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.

Jump to

Keyboard shortcuts

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