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) Aliases() []string
- 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) IsNil() bool
- func (a *Architecture) IsSet() bool
- func (a *Architecture) IsUnset() bool
- func (a *Architecture) IsX86() bool
- func (a *Architecture) MarshalYAML() (any, error)
- func (a *Architecture) Parse() error
- func (a *Architecture) ParseFrom(name string, comparisons ...func(string, string) bool) error
- func (a *Architecture) String() string
- func (a *Architecture) To32BitUserLand()
- func (a *Architecture) Type() string
- func (a *Architecture) UnmarshalYAML(node ast.Node) error
- func (a *Architecture) Version() int
- type Distribution
- func (d *Distribution) Is(other Distribution) bool
- func (d *Distribution) IsCompatibleWith(other Distribution) bool
- func (d *Distribution) IsNil() bool
- func (d *Distribution) IsUnset() bool
- func (d *Distribution) MarshalYAML() (any, error)
- func (d *Distribution) Parse() error
- func (d *Distribution) ParseFrom(name string, comparisons ...func(string, string) bool) error
- func (d *Distribution) String() string
- func (d *Distribution) UnmarshalYAML(node ast.Node) error
- type DistroInfo
- type Extension
- type Library
- func (l *Library) Default(os OS, distro Distribution) Library
- func (l *Library) Is(other Library) bool
- func (l *Library) IsCompatibleWith(other Library) bool
- func (l *Library) IsNil() bool
- func (l *Library) IsSet() bool
- func (l *Library) IsUnset() bool
- func (l *Library) MarshalYAML() (any, error)
- func (l *Library) Parse() error
- func (l *Library) ParseFrom(name string, comparisons ...func(string, string) bool) error
- func (l *Library) String() string
- func (l *Library) UnmarshalYAML(node ast.Node) error
- type LibraryInfo
- type OS
- func (o *OS) Is(other OS) bool
- func (o *OS) IsCompatibleWith(other OS) bool
- func (o *OS) IsNil() bool
- func (o *OS) IsUnset() bool
- func (o *OS) MarshalYAML() (any, error)
- func (o *OS) Parse() error
- func (o *OS) ParseFrom(name string, comparisons ...func(string, string) bool) error
- func (o *OS) String() string
- func (o *OS) Type() string
- func (o *OS) UnmarshalYAML(node ast.Node) error
- 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 ¶
type Architecture struct {
Name string `single:"true"`
// contains filtered or unexported fields
}
Architecture represents a CPU architecture configuration. Tracks architecture type, version, raw string, and user-land bitness.
func (*Architecture) Aliases ¶ added in v0.1.2
func (a *Architecture) Aliases() []string
Aliases returns all aliases for the architecture type.
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) IsNil ¶ added in v0.0.13
func (a *Architecture) IsNil() bool
IsNil returns true if the Architecture pointer is nil.
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) MarshalYAML ¶ added in v0.0.13
func (a *Architecture) MarshalYAML() (any, error)
MarshalYAML implements the yaml.Marshaler interface for Architecture.
func (*Architecture) Parse ¶
func (a *Architecture) Parse() error
Parse extracts operating system information from a string identifier.
func (*Architecture) ParseFrom ¶ added in v0.0.13
ParseFrom 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.
func (*Architecture) Type ¶
func (a *Architecture) Type() string
Type returns the canonical architecture type name.
func (*Architecture) UnmarshalYAML ¶ added in v0.0.13
func (a *Architecture) UnmarshalYAML(node ast.Node) error
UnmarshalYAML implements the yaml.Unmarshaler interface for Architecture.
func (*Architecture) Version ¶
func (a *Architecture) Version() int
Version returns the architecture version number.
type Distribution ¶
type Distribution struct {
Name string `single:"true"`
// contains filtered or unexported fields
}
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) IsNil ¶ added in v0.0.13
func (d *Distribution) IsNil() bool
IsNil returns true if the Distribution pointer is nil.
func (*Distribution) IsUnset ¶
func (d *Distribution) IsUnset() bool
IsUnset checks if the distribution type is empty.
func (*Distribution) MarshalYAML ¶ added in v0.0.13
func (d *Distribution) MarshalYAML() (any, error)
MarshalYAML implements the yaml.Marshaler interface for Distribution.
func (*Distribution) Parse ¶
func (d *Distribution) Parse() error
Parse extracts operating system information from a string identifier.
func (*Distribution) ParseFrom ¶ added in v0.0.13
ParseFrom 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.
func (*Distribution) UnmarshalYAML ¶ added in v0.0.13
func (d *Distribution) UnmarshalYAML(node ast.Node) error
UnmarshalYAML implements the yaml.Unmarshaler interface for 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.
type Library ¶
type Library struct {
Name string `single:"true"`
// contains filtered or unexported fields
}
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.
func (*Library) MarshalYAML ¶ added in v0.0.13
MarshalYAML implements the yaml.Marshaler interface for Library.
func (*Library) ParseFrom ¶ added in v0.0.13
ParseFrom extracts library information from a string identifier. Matches against known library types and aliases, setting type and raw values. Returns an error if parsing fails.
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 {
Name string `single:"true"`
// contains filtered or unexported fields
}
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).
func (*OS) MarshalYAML ¶ added in v0.0.13
MarshalYAML implements the yaml.Marshaler interface for OS.