system

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 13 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	OSWindows = "windows"
	OSLinux   = "linux"
	OSDarwin  = "darwin"
	OSFreeBSD = "freebsd"
	OSNetBSD  = "netbsd"
	OSIllumos = "illumos"
	OSSolaris = "solaris"
	OSOpenBSD = "openbsd"

	// OS Aliases
	OSMacOS = "macos"
	OSX     = "osx"

	// Base arches
	ArchX8664     = "x86_64"
	Arch386       = "386"
	ArchArm       = "arm"
	ArchArm64     = "arm64"
	ArchRiscV64   = "riscv64"
	ArchUniversal = "universal"

	// Not supported
	ArchS390X   = "s390x"   // IBM Z
	ArchPPC64LE = "ppc64le" // IBM Power (redhat naming)
	ArchPPC64EL = "ppc64el" // IBM Power (debian naming)
	ArchPPC64   = "ppc64"
	ArchLoong64 = "loong64" // LoongArch (go naming)

	// Rust target triple names
	ArchPowerPC64LE = "powerpc64le"
	ArchPowerPC64   = "powerpc64"
	ArchLoongArch64 = "loongarch64"
	ArchRiscV64GC   = "riscv64gc"

	// Aliases
	ArchArmHF   = "armhf"
	ArchArmV7   = "armv7"
	ArchArmV7HL = "armv7hl"
	ArchAarch64 = "aarch64"
	ArchAMD64   = "amd64"
	ArchX86     = "x86"
	ArchI686    = "i686"
	ArchI386    = "i386"
	Arch32Bit   = "32bit"
	Arch64Bit   = "64bit"
	ArchX64     = "x64"
)

Platform constants

View Source
const (
	PackageRPM = "rpm"
	PackageDeb = "deb"
	PackageApk = "apk"
	PackageDmg = "dmg"
	PackageMSI = "msi"
	PackageWhl = "whl" // Python wheel

	// Linux app bundles. Recognized so they are never mistaken for bare
	// binaries, but drop does not install them.
	PackageFlatpak  = "flatpak"
	PackageSnap     = "snap"
	PackageAppImage = "appimage"

	ArchiveZip  = "zip"
	ArchiveTar  = "tar"
	ArchiveBz2  = "bz2"
	ArchiveGz   = "gz"
	ArchiveXz   = "xz"
	ArchiveZst  = "zst"
	ArchiveRar  = "rar"
	ArchiveL7   = "l7"
	ArchiveTgz  = "tgz"  // gzipped tarball
	ArchiveTxz  = "txz"  // xz compressed tarball
	ArchiveTbz  = "tbz"  // bzip2 compressed tarball
	ArchiveTzst = "tzst" // zstd compressed tarball
	Archive7z   = "7z"
)

Recognized package types

View Source
const (
	OSFamilyAlpine     = "alpine"
	OSFamilyAlma       = "alma"
	OSFamilyArch       = "arch"
	OSFamilyDebian     = "debian"
	OSFamilyDistroless = "distroless"
	OSFamilyFedora     = "fedora"
	OSFamilyRocky      = "rocky"
	OSFamilyUbuntu     = "ubuntu"
	OSFamilyRHEL       = "rhel"
	OSFamilyWolfi      = "wolfi"

	OSFamilyMacOS   = "macos"
	OSFamilyWindows = "windows"
)

Operating system families

View Source
const (
	ExecutableELF   = "elf"
	ExecutableMachO = "macho"
	ExecutablePE    = "pe"
)

Executable formats recognized by their magic numbers

View Source
const ExecutableHeadSize = 8

ExecutableHeadSize is the number of leading bytes IsNativeExecutable needs to recognize every supported format.

Variables

View Source
var ArchAliases = map[string]LabelList{
	ArchX8664:   {ArchX8664, ArchAMD64, Arch64Bit, ArchX64, ArchX86},
	ArchArm64:   {ArchArm64, ArchAarch64},
	ArchArm:     {ArchArm, ArchArmHF, ArchArmV7, ArchArmV7HL},
	Arch386:     {Arch386, ArchI686, ArchI386, Arch32Bit},
	ArchRiscV64: {ArchRiscV64, ArchRiscV64GC},
	ArchS390X:   {ArchS390X},
	ArchPPC64LE: {ArchPPC64LE, ArchPPC64EL, ArchPPC64, ArchPowerPC64LE, ArchPowerPC64},
	ArchLoong64: {ArchLoong64, ArchLoongArch64},
}

Arch alias maps

View Source
var (
	FilenameSeparators = map[string]string{
		"-": "-", "_": "_", ".": ".",
	}
)
View Source
var OSAliases = map[string]LabelList{
	OSLinux:   {OSLinux},
	OSWindows: {OSWindows},
	OSDarwin:  {OSDarwin, OSMacOS, OSX},
	OSFreeBSD: {OSFreeBSD},
	OSNetBSD:  {OSNetBSD},
	OSIllumos: {OSIllumos},
	OSSolaris: {OSSolaris},
	OSOpenBSD: {OSOpenBSD},
}

OS alias maps

View Source
var PackageExtensions = ExtensionList{
	PackageRPM: {"rpm"},
	PackageDeb: {"deb"},
	PackageApk: {"apk"},
	PackageDmg: {"dmg"},
	PackageMSI: {"msi"},
	PackageWhl: {"whl"},

	PackageFlatpak:  {"flatpak"},
	PackageSnap:     {"snap"},
	PackageAppImage: {"AppImage", "appimage"},
}

Functions

func ExecutableFormat

func ExecutableFormat(head []byte) string

ExecutableFormat inspects the leading bytes of a file and returns the native executable format they announce, or an empty string when the data does not start with a known executable magic number.

func GetArch

func GetArch(label string) string

GetArch returns the "official" (according to this library) arch label from a string. If it does not match one of the known aliases it returns an empty string

func GetOS

func GetOS(label string) string

GetOS returns the "official" (according to this library) Os label from a string. If it does not match one of the known aliases it returns an empty string

func GetPreferredPackage

func GetPreferredPackage(family string) string

GetPreferredPackage returns the preferred package format for a system family

func GetSystemOSFamily

func GetSystemOSFamily() string

GetSystemOSFamily returns the constant representing the local system

func IsArchive

func IsArchive(filename string) bool

IsArchive takes a filename and returns true if it matches a known archive type

func IsNativeExecutable

func IsNativeExecutable(head []byte, osName string) bool

IsNativeExecutable returns true when the leading bytes of a file look like a native executable for the specified operating system: ELF for linux and the unix-likes, Mach-O for darwin and PE for windows. An empty OS matches any of the known formats. Detection is by content only, the executable permission bits are not taken into account.

func IsPackage

func IsPackage(filename string) bool

IsPackage takes a filename and returns true if it matches a known package type

func MainSplitPattern

func MainSplitPattern() string

MainSplitPattern dynamically builds a regex pattern with the know OS and arch patterns to split and parse filenames to deduct platform, kind and other data.

Types

type ExtensionList

type ExtensionList map[string][]string

func (*ExtensionList) GetTypeExtensionFromFile

func (el *ExtensionList) GetTypeExtensionFromFile(filename string) (fileType, extension string)

func (*ExtensionList) GetTypeFromFile

func (el *ExtensionList) GetTypeFromFile(filename string) string

type Info

type Info struct {
	Os     string
	Arch   string
	Family string
}

func GetInfo

func GetInfo() (*Info, error)

GetInfo returns information about the running system

type LabelList

type LabelList []string

LabelList is a list of os or arch labels.

func (*LabelList) ToRegex

func (ll *LabelList) ToRegex() *regexp.Regexp

Jump to

Keyboard shortcuts

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