os

package
v2.0.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package os provides remote OS release information detection

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultRegistry is the default OS release registry.
	DefaultRegistry = sync.OnceValue(func() *Registry {
		provider := NewRegistry()
		provider.Register(ResolveLinux)
		provider.Register(ResolveLinuxCompat)
		provider.Register(ResolveWindows)
		provider.Register(ResolveDarwin)
		return provider
	})

	// ErrNotRecognized is returned when the host OS is not recognized.
	ErrNotRecognized = errors.New("host OS not recognized")
)
View Source
var ErrArchNotDetected = errors.New("architecture not detected")

ErrArchNotDetected is returned by Arch when no architecture was detected during OS resolution.

View Source
var ErrUnrecognizedArch = errors.New("unrecognized architecture")

ErrUnrecognizedArch is returned by Arch when the raw architecture string is not a known value.

Functions

func RegisterDarwin

func RegisterDarwin(provider *Registry)

RegisterDarwin registers the darwin OS release resolver to a provider.

func RegisterLinux

func RegisterLinux(provider *Registry)

RegisterLinux registers the linux OS release resolver to a provider.

func RegisterLinuxCompat

func RegisterLinuxCompat(provider *Registry)

RegisterLinuxCompat registers the Linux compatibility resolver to a provider. It should be registered after ResolveLinux so it only activates when the standard os-release files are absent.

func RegisterWindows

func RegisterWindows(provider *Registry)

RegisterWindows registers the windows OS release resolver to a provider.

Types

type Factory

Factory is a function that returns an OS release based on the provided runner.

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider provides an interface to detect the operating system version and release information using the specified factory. The result is lazily initialized and memoized.

func NewOSReleaseProvider

func NewOSReleaseProvider(get ReleaseProvider, runner cmd.SimpleRunner) *Provider

NewOSReleaseProvider creates a new instance of Provider with the provided ReleaseProvider function and runner.

func (*Provider) OSRelease

func (p *Provider) OSRelease() (*Release, error)

OSRelease returns remote host operating system version and release information.

type Registry

Registry is a type that can determine the host OS given a runner.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new OS release registry.

type Release

type Release struct {
	ID          string            `kv:"ID"`
	IDLike      []string          `kv:"ID_LIKE,delim: "`
	Name        string            `kv:"NAME"`
	Version     string            `kv:"VERSION_ID"`
	ExtraFields map[string]string `kv:"*"`
	// contains filtered or unexported fields
}

Release describes host operating system version information.

func ResolveDarwin

func ResolveDarwin(conn cmd.SimpleRunner) (*Release, bool)

ResolveDarwin resolves the OS release information for a darwin host.

func ResolveLinux

func ResolveLinux(conn cmd.SimpleRunner) (*Release, bool)

ResolveLinux resolves the OS release information for a linux host.

func ResolveLinuxCompat

func ResolveLinuxCompat(conn cmd.SimpleRunner) (*Release, bool)

ResolveLinuxCompat is a fallback resolver for Linux hosts where /etc/os-release and /usr/lib/os-release are absent (distroless containers, minimal images, etc.). It probes for well-known package managers and synthesizes a *Release from the result. Unambiguous mappings (apk → alpine, pacman → arch, etc.) set ID directly; family-based managers set IDLike only, leaving ID as "linux", so downstream configurers can still match via the IDLike fallback chain.

func ResolveWindows

func ResolveWindows(conn cmd.SimpleRunner) (*Release, bool)

ResolveWindows resolves the OS release information for a windows host.

func (*Release) Arch

func (o *Release) Arch() (string, error)

Arch returns the host CPU architecture as a normalized GOARCH string (amd64, arm64, arm, 386). Returns ErrArchNotDetected if the architecture was not detected during OS resolution, or ErrUnrecognizedArch if the raw value is not a known architecture.

func (*Release) String

func (o *Release) String() string

String returns a human readable representation of the release information.

type ReleaseProvider

type ReleaseProvider func(cmd.SimpleRunner) (*Release, error)

ReleaseProvider is a function that returns OS release information given a runner.

Jump to

Keyboard shortcuts

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