Documentation
¶
Overview ¶
Package platform provides types and utilities for representing and working with different system platforms, including architectures, operating systems, libraries, and distributions. It allows for parsing, compatibility checks, and setting defaults for various platform components such as OS, architecture, library, and file extensions.
Index ¶
- Variables
- func Is32Bit() (bool, error)
- type ArchInfo
- type Architecture
- func (a *Architecture) Is(other Architecture) bool
- func (a *Architecture) Is64Bit() bool
- func (a *Architecture) IsARM() bool
- func (a *Architecture) IsCompatibleWith(other Architecture) bool
- func (a *Architecture) IsSet() bool
- func (a *Architecture) IsUnset() bool
- func (a *Architecture) IsX86() bool
- func (a *Architecture) Parse(name string) error
- func (a Architecture) String() string
- func (a *Architecture) To32BitUserLand()
- type Distribution
- type DistroInfo
- type Extension
- type Library
- type LibraryInfo
- type OS
- type OSInfo
Constants ¶
This section is empty.
Variables ¶
var ErrParse = errors.New("unable to parse")
ErrParse indicates a failure to parse platform-specific information.
Functions ¶
Types ¶
type ArchInfo ¶
ArchInfo defines an architecture's characteristics and parsing rules. Includes the canonical type name, known aliases, and version parsing logic.
type Architecture ¶
Architecture represents a CPU architecture configuration. Tracks architecture type, version, raw string, and user-land bitness.
func (*Architecture) Is ¶
func (a *Architecture) Is(other Architecture) bool
Is checks for exact architecture match including raw string. Returns true only if both architectures are set and identical.
func (*Architecture) Is64Bit ¶
func (a *Architecture) Is64Bit() bool
Is64Bit checks if the architecture is 64-bit capable. Returns true for amd64 and arm64 architectures.
func (*Architecture) IsARM ¶ added in v0.0.11
func (a *Architecture) IsARM() bool
IsARM checks if the architecture is ARM-based. Returns true for both 32-bit (arm) and 64-bit (arm64) variants.
func (*Architecture) IsCompatibleWith ¶
func (a *Architecture) IsCompatibleWith(other Architecture) bool
IsCompatibleWith checks if this architecture can run binaries built for another. Considers architecture type and version compatibility (e.g., armv7 can run armv5).
func (*Architecture) IsSet ¶ added in v0.0.11
func (a *Architecture) IsSet() bool
IsSet checks if the architecture type has been configured.
func (*Architecture) IsUnset ¶
func (a *Architecture) IsUnset() bool
IsUnset checks if the architecture type is empty.
func (*Architecture) IsX86 ¶ added in v0.0.11
func (a *Architecture) IsX86() bool
IsX86 checks if the architecture is x86-based. Returns true for both 32-bit (386) and 64-bit (amd64) variants.
func (*Architecture) Parse ¶
func (a *Architecture) Parse(name string) error
Parse extracts architecture information from a string identifier. Matches against known architecture types and aliases, setting type, version, and raw values. Returns an error if parsing fails.
func (Architecture) String ¶
func (a Architecture) String() string
String returns the canonical string representation of the architecture. Includes version information for ARM architectures (e.g., "armv7").
func (*Architecture) To32BitUserLand ¶
func (a *Architecture) To32BitUserLand()
To32BitUserLand converts a 64-bit architecture to its 32-bit equivalent. Handles amd64->386 and arm64->armv7 conversions for 32-bit userland support.
type Distribution ¶
type Distribution struct {
// Type is the canonical distribution name (e.g., debian, ubuntu).
Type string
// Raw contains the original string that was parsed.
Raw string
}
Distribution represents a Linux distribution configuration.
func Default ¶
func Default() Distribution
Default returns an empty Distribution configuration. Used as a fallback when distribution detection fails.
func (Distribution) Is ¶
func (d Distribution) Is(other Distribution) bool
Is checks for exact distribution match including raw string. Returns true only if both distributions are set and identical.
func (Distribution) IsCompatibleWith ¶
func (d Distribution) IsCompatibleWith(other Distribution) bool
IsCompatibleWith checks if this distribution can run binaries built for another. Currently checks only for exact type matches between distributions.
func (Distribution) IsUnset ¶
func (d Distribution) IsUnset() bool
IsUnset checks if the distribution type is empty.
func (*Distribution) Parse ¶
func (d *Distribution) Parse(name string) error
Parse extracts distribution information from a string identifier. Matches against known distribution types and aliases, setting type and raw values. Returns an error if parsing fails.
func (Distribution) String ¶
func (d Distribution) String() string
String returns the canonical name of the distribution.
type DistroInfo ¶
DistroInfo defines a Linux distribution's characteristics. Includes the canonical type name and known aliases.
func (DistroInfo) Supported ¶
func (DistroInfo) Supported() []DistroInfo
Supported returns the list of supported Linux distributions. Includes major distributions like Debian, Ubuntu, CentOS, and their aliases.
type Extension ¶
type Extension string
Extension represents a platform-specific file extension. Used primarily for executable files and archive formats.
func (*Extension) Default ¶
Default returns the platform's standard executable extension. Returns ".exe" for Windows systems and empty string for Unix-like systems.
type Library ¶
type Library struct {
// Type is the canonical library name (e.g., gnu, musl, msvc).
Type string
// Raw contains the original string that was parsed.
Raw string
}
Library represents a system's standard library or ABI configuration.
func (*Library) Default ¶
func (l *Library) Default(os OS, distro Distribution) Library
Default determines the standard library for a platform. Uses OS and distribution information to select the appropriate system library (e.g., GNU for Linux, MSVC for Windows).
func (Library) Is ¶
Is checks for exact library match including raw string. Returns true only if both libraries are set and identical.
func (Library) IsCompatibleWith ¶
IsCompatibleWith checks if binaries built against this library can run with another library. Uses a compatibility matrix to determine binary compatibility between different library implementations.
type LibraryInfo ¶
LibraryInfo defines a system library's characteristics. Includes the canonical type name and known aliases.
func (LibraryInfo) Supported ¶
func (LibraryInfo) Supported() []LibraryInfo
Supported returns the list of supported system libraries. Includes major libraries like GNU, Musl, MSVC, and their aliases.
type OS ¶
type OS struct {
// Type is the canonical OS name (e.g., linux, windows, darwin).
Type string
// Raw contains the original string that was parsed.
Raw string
}
OS represents an operating system configuration.
func (*OS) Is ¶
Is checks for exact OS match including raw string. Returns true only if both OS configurations are set and identical.
func (*OS) IsCompatibleWith ¶
IsCompatibleWith checks if binaries built for this OS can run on another. Currently requires exact OS type matches (e.g., linux-linux, windows-windows).