Documentation
¶
Index ¶
- func GetAllGroups() ([]types.GroupInfo, error)
- func GetAllUsers(includeNoLogin bool) ([]types.UserInfo, error)
- func GetProcessInfo(pid int) (*types.Process, error)
- func GetProcessList() ([]types.Process, error)
- func GetSupportedTimezones() ([]types.Timezone, error)
- func GetSystemInfo() (*types.SystemInfo, error)
- func GetUsers(usernames []string, uids []string, useUID bool) map[string]types.UserInfo
- func KillProcess(pid int) error
- func RunningInBareMetal() bool
- func RunningInContainer() bool
- func RunningInVM() bool
- func RunningInVMOrContainer() bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetAllGroups ¶
GetAllGroups retrieves information about all groups on the system by parsing /etc/group.
Example:
groups, err := system.GetGroups() if err != nil { fmt.Printf("Error: %v\n", err) return } for _, group := range groups { fmt.Printf("GID: %s\n", group.GID) fmt.Printf("Name: %s\n", group.Name) }
func GetAllUsers ¶
GetAllUsers retrieves information about all users on the system by parsing /etc/passwd. If includeNoLogin is true, users with /usr/sbin/nologin as their shell will be included.
Example:
users, err := system.GetAllUsers(false) if err != nil { fmt.Printf("Error: %v\n", err) return } for _, user := range users { fmt.Printf("UID: %s\n", user.UID) fmt.Printf("Username: %s\n", user.Username) }
func GetProcessInfo ¶
GetProcessInfo returns information about a specific process.
Example:
process, err := system.GetProcessInfo(1) if err != nil { fmt.Printf("Error: %v\n", err) return } fmt.Printf("PID: %d\n", process.PID) fmt.Printf("Name: %s\n", process.Name) fmt.Printf("State: %s\n", process.State)
func GetProcessList ¶
GetProcessList returns a list of all processes running on the system.
Example:
processes, err := system.GetProcessList() if err != nil { fmt.Printf("Error: %v\n", err) return } for _, process := range processes { fmt.Printf("PID: %d\n", process.PID) fmt.Printf("Name: %s\n", process.Name) fmt.Printf("State: %s\n", process.State) }
func GetSupportedTimezones ¶
GetSupportedTimezones returns a list of supported timezones. The list is generated by reading the contents of /usr/share/zoneinfo.
Example:
timezones, err := system.GetSupportedTimezones() if err != nil { fmt.Printf("Error: %v\n", err) return } for _, timezone := range timezones { fmt.Printf("%s\n", timezone.Name) fmt.Printf("%s\n", timezone.Location) }
func GetSystemInfo ¶
func GetSystemInfo() (*types.SystemInfo, error)
GetSystemInfo returns information about the system, such as OS, version, codename, architecture and machine type. If the machine type cannot be determined, it will be set to BareMetal. If any error occurs, it will be returned.
Example:
info, err := system.GetSystemInfo() if err != nil { fmt.Printf("Error: %v\n", err) return } fmt.Printf("OS: %s\n", info.OS)
func GetUsers ¶
GetUsers retrieves users with the given usernames and UIDs. If useUID is true, the returned map will use the UID as the key, otherwise it will use the username as the key.
Example:
users, err := system.GetUsers([]string{"john", "jane"}, []string{"1000"}) if err != nil { fmt.Printf("Error: %v\n", err) return } for _, user := range users { fmt.Printf("UID: %s\n", user.UID) fmt.Printf("Username: %s\n", user.Username) }
Notes:
if a username and UID refer to the same user, the user will only be returned once. If an user does not match any of the given usernames or UIDs, it will not be available in the returned map.
func KillProcess ¶
KillProcess terminates a process given its PID.
Example:
err := system.KillProcess(2024) if err != nil { fmt.Printf("Error: %v\n", err) return }
func RunningInBareMetal ¶
func RunningInBareMetal() bool
RunningInBareMetal returns true if the system is running on bare metal, otherwise it returns false.
Example:
if system.RunningInBareMetal() { fmt.Println("Running on bare metal") } else { fmt.Println("Not running on bare metal") }
func RunningInContainer ¶
func RunningInContainer() bool
RunningInContainer returns true if the system is running in a container, otherwise it returns false.
Example:
if system.RunningInContainer() { fmt.Println("Running in a container") } else { fmt.Println("Not running in a container") }
func RunningInVM ¶
func RunningInVM() bool
RunningInVM returns true if the system is running in a virtual machine, otherwise it returns false.
Example:
if system.RunningInVM() { fmt.Println("Running in a virtual machine") } else { fmt.Println("Not running in a virtual machine") }
func RunningInVMOrContainer ¶
func RunningInVMOrContainer() bool
RunningInVMOrContainer returns true if the system is running in a virtual machine or a container, otherwise it returns false.
Example:
if system.RunningInVMOrContainer() { fmt.Println("Running in a virtual machine or a container") } else { fmt.Println("Not running in a virtual machine or a container") }
Types ¶
This section is empty.