system

package
v0.0.29 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2023 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareOsEnv added in v0.0.17

func CompareOsEnv(key, comparedEnv string) bool

CompareOsEnv gets env named by the key and compare it with comparedEnv. Play: https://go.dev/play/p/BciHrKYOHbp

func ExecCommand added in v0.0.17

func ExecCommand(command string, opts ...Option) (stdout, stderr string, exitCode int, err error)

ExecCommand execute command, return the stdout and stderr string and exitCode of command, and error if error occur param `command` is a complete command string, like, ls -a (linux), dir(windows), ping 127.0.0.1 in linux, use /bin/bash -c to execute command in windows, use powershell.exe to execute command Play: https://go.dev/play/p/n-2fLyZef-4

func GetAllIP

func GetAllIP() (map[string][]string, error)

获取本机所有的IP, 效果等同于 ip addr | grep inet | awk -F " " '{ print $2}'

func GetAllIPV4Slice

func GetAllIPV4Slice() ([]string, error)

获取本机所有IPv4地址

func GetExecDir added in v0.0.11

func GetExecDir() (string, error)

获取进程当前的运行目录

func GetHomeDir added in v0.0.5

func GetHomeDir() string

func GetHostInfo

func GetHostInfo() (host.InfoStat, error)

获取系统信息

func GetOsBits added in v0.0.17

func GetOsBits() int

GetOsBits return current os bits (32 or 64). Play: https://go.dev/play/p/ml-_XH3gJbW

func GetOsEnv added in v0.0.17

func GetOsEnv(key string) string

GetOsEnv gets the value of the environment variable named by the key. Play: https://go.dev/play/p/D88OYVCyjO-

func GetOutboundIP

func GetOutboundIP() (string, error)

获取本机首选IP地址

func GetOutboundIPByInterfaceAndRoute added in v0.0.18

func GetOutboundIPByInterfaceAndRoute() (string, error)

获取本机首选IP地址的另一种备选方案

func IsLinux added in v0.0.17

func IsLinux() bool

IsLinux check if current os is linux. Play: https://go.dev/play/p/zIflQgZNuxD

func IsMac added in v0.0.17

func IsMac() bool

IsMac check if current os is macos. Play: https://go.dev/play/p/Mg4Hjtyq7Zc

func IsWindows added in v0.0.17

func IsWindows() bool

IsWindows check if current os is windows. Play: https://go.dev/play/p/XzJULbzmf9m

func RandomPort

func RandomPort(blackList []uint16) uint16

随机选取可用的端口号

func RandomSubnetIP

func RandomSubnetIP() string

随机生成一个IP网段

func RandomSubnetIPWithBlackList

func RandomSubnetIPWithBlackList(blackList []string) string

带黑名单的生成随机IP网段

func RemoveOsEnv added in v0.0.17

func RemoveOsEnv(key string) error

RemoveOsEnv remove a single environment variable. Play: https://go.dev/play/p/fqyq4b3xUFQ

func SetOsEnv added in v0.0.17

func SetOsEnv(key, value string) error

SetOsEnv sets the value of the environment variable named by the key. Play: https://go.dev/play/p/D88OYVCyjO-

func VerifyPortIsUnused

func VerifyPortIsUnused(port uint16) (bool, error)

校验端口是否被使用,端口未使用则返回true

func VerifyRuntimeEnv

func VerifyRuntimeEnv() (string, error)

检查运行环境类型, Linux主机、K8S的Pod、Docker容器 - host: Linux主机 - pod: K8S的Pod - container: Docker容器 - unknown: 其他未知的情况

Types

type CurrentUserInfo added in v0.0.2

type CurrentUserInfo struct {
	Username string
	Name     string
	HomeDir  string
	Uid      string
	Gid      string
}

func GetCurrentUserInfo added in v0.0.2

func GetCurrentUserInfo() (CurrentUserInfo, error)

获取当前用户信息

type NetInterfaceInfo added in v0.0.18

type NetInterfaceInfo struct {
	Index        int    // positive integer that starts at one, zero is never used
	MTU          int    // maximum transmission unit
	Name         string // e.g., "en0", "lo0", "eth0.100"
	HardwareAddr string // IEEE MAC-48, EUI-48 and EUI-64 form
	Flags        string // e.g., FlagUp, FlagLoopback, FlagMulticast
	IPV4Addr     string
	IPV6Addr     string
}

func GetNetInterfacesInfo added in v0.0.18

func GetNetInterfacesInfo() ([]NetInterfaceInfo, error)

获取本机所有网卡对应的IP地址信息

type Option added in v0.0.17

type Option func(*exec.Cmd)

func WithForeground added in v0.0.17

func WithForeground() Option

func WithWinHide added in v0.0.17

func WithWinHide() Option

Jump to

Keyboard shortcuts

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