system

package
v0.0.0-...-7fbf2ce Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: GPL-3.0 Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAllGroups

func GetAllGroups() ([]types.GroupInfo, error)

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

func GetAllUsers(includeNoLogin bool) ([]types.UserInfo, error)

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

func GetProcessInfo(pid int) (*types.Process, error)

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

func GetProcessList() ([]types.Process, error)

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

func GetSupportedTimezones() ([]types.Timezone, error)

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

func GetUsers(usernames []string, uids []string, useUID bool) map[string]types.UserInfo

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

func KillProcess(pid int) error

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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