Documentation
¶
Overview ¶
Package osdetect provides utilities for detecting operating system information. This file contains the Linux-specific implementation.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetKernelVersion ¶
GetKernelVersion returns the Linux kernel version string (e.g., "6.8.0-45-generic"). It reads this information directly from /proc/sys/kernel/osrelease.
Types ¶
type Family ¶
type Family string
Family represents the broad category of the operating system.
const ( // Linux represents any Linux-based operating system. Linux Family = "linux" // Windows represents Microsoft Windows operating systems. Windows Family = "windows" // Darwin represents Apple macOS operating systems. Darwin Family = "darwin" // Unknown represents an operating system that could not be identified. Unknown Family = "unknown" )
type Info ¶
type Info struct {
// Family is the broad OS category (linux, windows, darwin, unknown).
Family Family
// Arch is the architecture of the OS, matching runtime.GOARCH (e.g., "amd64", "arm64", "386").
Arch string
// Name is a human-friendly name of the OS (e.g., "Ubuntu", "Windows 11 Pro").
Name string
// Version is the best "primary" version string available (e.g., "22.04", "10.0.22631").
Version string
// Kernel is the kernel or build version, if available (e.g., "5.15.0-91-generic").
Kernel string
// Linux contains detailed information if Family is Linux.
// It is nil for other OS families.
Linux *LinuxInfo `json:",omitempty"`
// Windows contains detailed information if Family is Windows.
// It is nil for other OS families.
Windows *WindowsInfo `json:",omitempty"`
// Raw holds unparsed key/value pairs read from the source (e.g., /etc/os-release or registry).
// This is useful for debugging or accessing fields not modeled by this library.
Raw map[string]string `json:",omitempty"`
}
Info encapsulates the detected information about the operating system. It provides a high-level summary and detailed, OS-specific information.
type LinuxInfo ¶
type LinuxInfo struct {
// Distro is the machine-readable ID field (e.g., "ubuntu", "debian", "fedora", "arch").
Distro string
// DistroLike represents the ID_LIKE field, indicating closely related distributions (e.g., "debian" for Ubuntu).
DistroLike string
// PrettyName is a human-readable string identifying the OS (e.g., "Ubuntu 22.04.3 LTS").
PrettyName string
// VersionID is a machine-readable string identifying the OS version (e.g., "22.04").
VersionID string
// Codename is a machine-readable string identifying the OS version codename (e.g., "jammy").
Codename string
// Kernel is the kernel release string, typically from uname -r or /proc/sys/kernel/osrelease.
Kernel string
}
LinuxInfo holds distribution-specific details for Linux systems. This information is typically sourced from /etc/os-release.
type OSReleaseInfo ¶
OSReleaseInfo represents the parsed key-value pairs from an os-release file.
func ParseRelease ¶
func ParseRelease() (OSReleaseInfo, error)
ParseRelease reads and parses the /etc/os-release file. It extracts key-value pairs according to the standard os-release format and returns them as an OSReleaseInfo map.
func (OSReleaseInfo) GetField ¶
func (o OSReleaseInfo) GetField(key, defaultValue string) string
GetField returns the value of the specified key. If the key is not found or its value is empty, it returns the defaultValue.
func (OSReleaseInfo) GetID ¶
func (o OSReleaseInfo) GetID() string
GetID returns the ID field, which is a machine-readable string identifying the distribution (e.g., "ubuntu", "debian", "fedora").
func (OSReleaseInfo) GetPrettyName ¶
func (o OSReleaseInfo) GetPrettyName() string
GetPrettyName returns the PRETTY_NAME field, which is typically the most user-friendly name of the distribution (e.g., "Ubuntu 22.04.3 LTS"). If PRETTY_NAME is empty, it falls back to the NAME field.
func (OSReleaseInfo) GetVersion ¶
func (o OSReleaseInfo) GetVersion() string
GetVersion returns the value of the VERSION field.
func (OSReleaseInfo) GetVersionID ¶
func (o OSReleaseInfo) GetVersionID() string
GetVersionID returns the VERSION_ID field, which is a machine-readable string identifying the operating system version (e.g., "22.04", "36").
type WindowsInfo ¶
type WindowsInfo struct {
// Edition is the specific edition of Windows (e.g., "Pro", "Home", "Enterprise", "ServerDatacenter").
Edition string
// Build is the Windows build number (e.g., "22631").
Build string
// DisplayVersion is the user-facing version name (e.g., "23H2", "22H2").
DisplayVersion string
// ProductName is the full product name string as found in the registry (e.g., "Windows 10 Pro").
ProductName string
// IsServer indicates whether the operating system is a Windows Server edition.
IsServer bool
}
WindowsInfo holds detailed information specific to Windows systems. This information is often sourced from the Windows Registry or WMI.