platform

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2025 License: MIT Imports: 10 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var ErrParse = errors.New("unable to parse")

ErrParse indicates a failure to parse platform-specific information.

Functions

func Is32Bit

func Is32Bit() (bool, error)

Is32Bit detects if the system is running in 32-bit mode. Uses getconf to determine the system's bit width.

Types

type ArchInfo

type ArchInfo struct {
	Parse   func(string) (int, error)
	Type    string
	Aliases []string
}

ArchInfo defines an architecture's characteristics and parsing rules. Includes the canonical type name, known aliases, and version parsing logic.

func (ArchInfo) Supported

func (ArchInfo) Supported() []ArchInfo

Supported returns the list of supported CPU architectures. Includes x86, ARM architectures and their variants with parsing rules.

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

func (a *Architecture) ParseFrom(name string, comparisons ...func(string, string) bool) error

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

func (d *Distribution) ParseFrom(name string, comparisons ...func(string, string) bool) error

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

type DistroInfo struct {
	Type    string
	Aliases []string
}

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) IsNil added in v0.0.13

func (e *Extension) IsNil() bool

IsNil returns true if the Extension is empty.

func (*Extension) ParseFrom added in v0.0.13

func (e *Extension) ParseFrom(os OS)

ParseFrom returns the platform's standard executable extension. Returns ".exe" for Windows systems and empty string for Unix-like systems.

func (*Extension) String

func (e *Extension) String() string

String returns the extension value including the leading dot.

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

func (l *Library) Is(other Library) bool

Is checks for exact library match including raw string. Returns true only if both libraries are set and identical.

func (*Library) IsCompatibleWith

func (l *Library) IsCompatibleWith(other Library) bool

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) IsNil added in v0.0.13

func (l *Library) IsNil() bool

IsNil returns true if the Library pointer is nil.

func (*Library) IsSet added in v0.0.11

func (l *Library) IsSet() bool

IsSet checks if the library type has been configured.

func (*Library) IsUnset

func (l *Library) IsUnset() bool

IsUnset checks if the library type is empty.

func (*Library) MarshalYAML added in v0.0.13

func (l *Library) MarshalYAML() (any, error)

MarshalYAML implements the yaml.Marshaler interface for Library.

func (*Library) Parse

func (l *Library) Parse() error

Parse extracts operating system information from a string identifier.

func (*Library) ParseFrom added in v0.0.13

func (l *Library) ParseFrom(name string, comparisons ...func(string, string) bool) error

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.

func (*Library) String

func (l *Library) String() string

String returns the canonical name of the library.

func (*Library) UnmarshalYAML added in v0.0.13

func (l *Library) UnmarshalYAML(node ast.Node) error

UnmarshalYAML implements the yaml.Unmarshaler interface for Library.

type LibraryInfo

type LibraryInfo struct {
	Type    string
	Aliases []string
}

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

func (o *OS) Is(other OS) bool

Is checks for exact OS match including raw string. Returns true only if both OS configurations are set and identical.

func (*OS) IsCompatibleWith

func (o *OS) IsCompatibleWith(other OS) bool

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) IsNil added in v0.0.13

func (o *OS) IsNil() bool

IsNil returns true if the OS pointer is nil.

func (*OS) IsUnset

func (o *OS) IsUnset() bool

IsUnset checks if the OS type is empty.

func (*OS) MarshalYAML added in v0.0.13

func (o *OS) MarshalYAML() (any, error)

MarshalYAML implements the yaml.Marshaler interface for OS.

func (*OS) Parse

func (o *OS) Parse() error

Parse extracts operating system information from a string identifier.

func (*OS) ParseFrom added in v0.0.13

func (o *OS) ParseFrom(name string, comparisons ...func(string, string) bool) error

ParseFrom extracts OS information from a string identifier.

func (*OS) String

func (o *OS) String() string

String returns the canonical name of the operating system.

func (*OS) Type

func (o *OS) Type() string

Type returns the canonical OS type name.

func (*OS) UnmarshalYAML added in v0.0.13

func (o *OS) UnmarshalYAML(node ast.Node) error

UnmarshalYAML implements the yaml.Unmarshaler interface for OS.

type OSInfo

type OSInfo struct {
	Type    string
	Aliases []string
}

OSInfo defines an operating system's characteristics. Includes the canonical type name and known aliases.

func (OSInfo) Supported

func (OSInfo) Supported() []OSInfo

Supported returns the list of supported operating systems. Includes major operating systems like Linux, macOS, Windows, and various BSD variants with their common aliases.

Jump to

Keyboard shortcuts

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