Skip to content

Introduction ​

Operating system utility module, providing platform detection, OS information retrieval, and user directory lookup functionality. Determines the current operating system based on runtime.GOOS, gets detailed platform information via gopsutil/host, and supports cross-platform (Windows, Linux, macOS) user home directory lookup.

Import ​

go
import "github.com/wallace5303/ee-go/eos"

API ​

IsWindows() ​

Description: Check whether the current runtime environment is a Windows system. Detected via runtime.GOOS, returns true when it is "windows".

Parameters: None

Returns: bool — true indicates the current system is Windows, false indicates it is not

Example:

go
if eos.IsWindows() {
    fmt.Println("Currently running on Windows system")
}

IsLinux() ​

Description: Check whether the current runtime environment is a Linux system. Detected via runtime.GOOS, returns true when it is "linux".

Parameters: None

Returns: bool — true indicates the current system is Linux, false indicates it is not

Example:

go
if eos.IsLinux() {
    fmt.Println("Currently running on Linux system")
}

IsMacOS() ​

Description: Check whether the current runtime environment is a macOS system. Detected via runtime.GOOS, returns true when it is "darwin". Identical functionality to IsDarwin().

Parameters: None

Returns: bool — true indicates the current system is macOS, false indicates it is not

Example:

go
if eos.IsMacOS() {
    fmt.Println("Currently running on macOS system")
}

See also: IsDarwin()

IsDarwin() ​

Description: Check whether the current runtime environment is a Darwin (macOS) system. Detected via runtime.GOOS, returns true when it is "darwin". Identical functionality to IsMacOS(), providing an alias from the Darwin kernel name perspective.

Parameters: None

Returns: bool — true indicates the current system is Darwin/macOS, false indicates it is not

Example:

go
if eos.IsDarwin() {
    fmt.Println("Currently running on Darwin system")
}

See also: IsMacOS()

OSPlatform() ​

Description: Get the detailed platform name of the current operating system. Retrieved via gopsutil/host.PlatformInformation(), such as "ubuntu", "windows", "darwin", etc. Returns "Unknown" on failure.

Parameters: None

Returns: string — operating system platform name string, "Unknown" on failure

Example:

go
platform := eos.OSPlatform()
fmt.Printf("Current platform: %s\n", platform)
// Output: Current platform: ubuntu  or  Current platform: darwin  or  Current platform: windows

GetUserHomeDir() ​

Description: Get the current user's home directory path. Prioritizes user.Current(); for cross-platform cross-compilation, Windows uses HOMEDRIVE + HOMEPATH or USERPROFILE environment variables, Unix uses HOME environment variable or shell commands.

Parameters: None

Returns:

Return valueTypeDescription
homeDirstringUser home directory absolute path
errerrorError information on failure; nil on success

Example:

go
homeDir, err := eos.GetUserHomeDir()
if err != nil {
    fmt.Printf("Failed to get user directory: %s\n", err)
    return
}
fmt.Printf("User home directory: %s\n", homeDir)
// Output: User home directory: /home/user  or  User home directory: C:\Users\user

See also: eruntime.UserHomeDir