platform

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2025 License: MIT Imports: 8 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 {
	Type            string
	Raw             string
	Version         int
	Is32BitUserLand bool
}

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

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) Default

func (e *Extension) Default(os OS) Extension

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

func (*Extension) Parse

func (e *Extension) Parse(name string) error

Parse extracts the file extension from a filename. Handles special cases like ".tar.gz" compound extensions.

func (Extension) String

func (e Extension) String() string

String returns the extension value including the leading dot.

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

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) 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) Parse

func (l *Library) Parse(name string) error

Parse 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.

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 {
	// 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

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) IsUnset

func (o *OS) IsUnset() bool

IsUnset checks if the OS type is empty.

func (*OS) Parse

func (o *OS) Parse(name string) error

Parse extracts operating system information from a string identifier. Matches against known OS types and aliases, setting type and raw values. Returns an error if parsing fails.

func (OS) String

func (o OS) String() string

String returns the canonical name of the operating system.

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