Documentation ¶
Index ¶
- Constants
- Variables
- func BubbleSort(arr []float64)
- func CompareFile(file1Path string, file2Path string) (bool, error)
- func CreateDir(dirPath string) error
- func CreateFile(filePath string) error
- func DeleteFile(filePath string) error
- func FileEmpty(filePath string) bool
- func FileExist(filePath string) bool
- func FolderEmpty(dirPath string) bool
- func FormatFloat(value float64, precision int) string
- func GetAbsPath(filePath string) string
- func GetBIOSInfo(sysInfo sysinfo.SysInfo) map[string]interface{}
- func GetBoardInfo(sysInfo sysinfo.SysInfo) map[string]interface{}
- func GetCPUInfo(sysInfo sysinfo.SysInfo, dataUnit string) map[string]interface{}
- func GetColor() int
- func GetCurrentUserInfo() (*user.User, error)
- func GetGPUInfo() map[string]interface{}
- func GetHostname() string
- func GetLanguage() string
- func GetLoadInfo() map[string]interface{}
- func GetMemoryInfo(dataUnit string, percentUnit string) map[string]interface{}
- func GetNicInfo() map[string]interface{}
- func GetOSInfo(sysInfo sysinfo.SysInfo) map[string]interface{}
- func GetProductInfo(sysInfo sysinfo.SysInfo) map[string]interface{}
- func GetStorageInfo() map[string]interface{}
- func GetSwapInfo(dataUnit string) map[string]interface{}
- func GetTimeInfo() (map[string]interface{}, error)
- func GetTomlConfig(filePath string) (*toml.Tree, error)
- func GetUpdateDaemonInfo() (map[string]interface{}, error)
- func GetUpdateInfo(filePath string, line int) ([]string, error)
- func GetUserInfo() map[string]interface{}
- func GetUserInfoById(userId int) (*user.User, error)
- func GetUserInfoByName(userName string) (*user.User, error)
- func GetVariable(key string) string
- func GoToDir(dirPath string) error
- func Human(size float64, initialUnit string) (float64, string)
- func ProgramInfo() map[string]string
- func ReadFileCount(file, key string) int
- func ReadFileKey(file, key string) string
- func ReadFileLine(file string, line int) string
- func RunCommand(command string, args []string) error
- func RunCommandGetResult(command string, args []string) (string, error)
- func SetVariable(key, value string) error
- func UnixTime2DayHourMinuteSecond(unixTime uint64) (day, hour, minute, second uint64)
- func UnixTime2TimeString(unixTime uint64) string
- func UpperStringFirstChar(str string) string
- func WriteFile(filePath string, content string) error
- func WriteTomlConfig(filePath string) (int64, error)
- type Config
- type CpuConfig
- type GenealogyConfig
- type MainConfig
- type MemoryConfig
- type UpdateConfig
Constants ¶
const ( Name string = "Eniac" // 程序名 Version string = "v1.4.1" // 程序版本 Project string = "github.com/yhyj/eniac" // 项目地址 )
Variables ¶
var ( FgBlackText = color.FgBlack.Render // 前景色 - 黑色 FgWhiteText = color.FgWhite.Render // 前景色 - 白色 FgLightWhiteText = color.FgLightWhite.Render // 前景色 - 亮白色 FgGrayText = color.FgGray.Render // 前景色 - 灰色 FgRedText = color.FgRed.Render // 前景色 - 红色 FgLightRedText = color.FgLightRed.Render // 前景色 - 亮红色 FgGreenText = color.FgGreen.Render // 前景色 - 绿色 FgLightGreenText = color.FgLightGreen.Render // 前景色 - 亮绿色 FgYellowText = color.FgYellow.Render // 前景色 - 黄色 FgLightYellowText = color.FgLightYellow.Render // 前景色 - 亮黄色 FgBlueText = color.FgBlue.Render // 前景色 - 蓝色 FgLightBlueText = color.FgLightBlue.Render // 前景色 - 亮蓝色 FgMagentaText = color.FgMagenta.Render // 前景色 - 品红 FgLightMagentaText = color.FgLightMagenta.Render // 前景色 - 亮品红 FgCyanText = color.FgCyan.Render // 前景色 - 青色 FgLightCyanText = color.FgLightCyan.Render // 前景色 - 亮青色 BgBlackText = color.BgBlack.Render // 背景色 - 黑色 BgWhiteText = color.BgWhite.Render // 背景色 - 白色 BgLightWhiteText = color.BgLightWhite.Render // 背景色 - 亮白色 BgGrayText = color.BgGray.Render // 背景色 - 灰色 BgRedText = color.BgRed.Render // 背景色 - 红色 BgLightRedText = color.BgLightRed.Render // 背景色 - 亮红色 BgGreenText = color.BgGreen.Render // 背景色 - 绿色 BgLightGreenText = color.BgLightGreen.Render // 背景色 - 亮绿色 BgYellowText = color.BgYellow.Render // 背景色 - 黄色 BgLightYellowText = color.BgLightYellow.Render // 背景色 - 亮黄色 BgBlueText = color.BgBlue.Render // 背景色 - 蓝色 BgLightBlueText = color.BgLightBlue.Render // 背景色 - 亮蓝色 BgMagentaText = color.BgMagenta.Render // 背景色 - 品红 BgLightMagentaText = color.BgLightMagenta.Render // 背景色 - 亮品红 BgCyanText = color.BgCyan.Render // 背景色 - 青色 BgLightCyanText = color.BgLightCyan.Render // 背景色 - 亮青色 InfoText = color.Info.Render // Info 文本 NoteText = color.Note.Render // Note 文本 LightText = color.Light.Render // Light 文本 ErrorText = color.Error.Render // Error 文本 DangerText = color.Danger.Render // Danger 文本 NoticeText = color.Notice.Render // Notice 文本 SuccessText = color.Success.Render // Success 文本 CommentText = color.Comment.Render // Comment 文本 PrimaryText = color.Primary.Render // Primary 文本 WarnText = color.Warn.Render // Warn 文本 QuestionText = color.Question.Render // Question 文本 SecondaryText = color.Secondary.Render // Secondary 文本 )
var ( GitCommitHash string = "Unknown" // Git 提交 Hash BuildTime string = "Unknown" // 编译时间 BuildBy string = "Unknown" // 编译者 )
var Arch = runtime.GOARCH // 系统架构
var GenealogyName = map[string]map[string]string{
"BIOSVendor": {"zh": "BIOS 厂商", "en": "Vendor"},
"BIOSVersion": {"zh": "BIOS 版本", "en": "Version"},
"BIOSDate": {"zh": "BIOS 发布", "en": "Date"},
"BoardVendor": {"zh": "主板厂商", "en": "Vendor"},
"BoardName": {"zh": "主板名称", "en": "Name"},
"BoardVersion": {"zh": "主板版本", "en": "Version"},
"CPUModel": {"zh": "处理器型号", "en": "Model"},
"CPUNumber": {"zh": "处理器数量", "en": "Number"},
"CPUCores": {"zh": "处理器核心", "en": "Cores"},
"CPUThreads": {"zh": "处理器线程", "en": "Threads"},
"CPUCache": {"zh": "处理器缓存", "en": "Cache"},
"GPUAddress": {"zh": "显卡地址", "en": "Address"},
"GPUDriver": {"zh": "显卡驱动", "en": "Driver"},
"GPUProduct": {"zh": "显卡型号", "en": "Product"},
"GPUVendor": {"zh": "显卡厂商", "en": "Vendor"},
"OS": {"zh": "操作系统", "en": "OS"},
"Arch": {"zh": "系统架构", "en": "Arch"},
"Kernel": {"zh": "内核版本", "en": "Kernel"},
"Platform": {"zh": "系统类型", "en": "Platform"},
"Hostname": {"zh": "主机名称", "en": "Hostname"},
"TimeZone": {"zh": "时区", "en": "Time zone"},
"Load1": {"zh": "1分钟平均负载", "en": "Load average (1 min)"},
"Load5": {"zh": "5分钟平均负载", "en": "Load average (5 min)"},
"Load15": {"zh": "15分钟平均负载", "en": "Load average (15 min)"},
"NicName": {"zh": "网卡名称", "en": "Name"},
"NicPCIAddress": {"zh": "PCI 地址", "en": "PCI Address"},
"NicMacAddress": {"zh": "MAC 地址", "en": "MAC Address"},
"NicSpeed": {"zh": "网卡速率", "en": "Speed"},
"NicDuplex": {"zh": "工作模式", "en": "Duplex"},
"NicDriver": {"zh": "网卡驱动", "en": "Driver"},
"NicProduct": {"zh": "网卡型号", "en": "Product"},
"NicVendor": {"zh": "网卡厂商", "en": "Vendor"},
"MemoryTotal": {"zh": "内存大小", "en": "Total"},
"MemoryUsed": {"zh": "已用内存", "en": "Used"},
"MemoryUsedPercent": {"zh": "内存占用", "en": "Used Percent"},
"MemoryFree": {"zh": "空闲内存", "en": "Free"},
"MemoryShared": {"zh": "共享内存", "en": "Shared"},
"MemoryBuffCache": {"zh": "缓冲内存", "en": "Buff Cache"},
"MemoryAvail": {"zh": "可用内存", "en": "Avail"},
"SwapDisabled": {"zh": "交换空间未启用", "en": "Swap Disabled"},
"SwapTotal": {"zh": "交换空间大小", "en": "Total"},
"SwapFree": {"zh": "空闲交换空间", "en": "Free"},
"Process": {"zh": "进程数", "en": "Process"},
"ProductVendor": {"zh": "设备厂商", "en": "Vendor"},
"ProductName": {"zh": "设备名称", "en": "Name"},
"StorageName": {"zh": "磁盘名称", "en": "Name"},
"StorageType": {"zh": "磁盘类型", "en": "Type"},
"StorageDriver": {"zh": "磁盘驱动", "en": "Driver"},
"StorageVendor": {"zh": "磁盘厂商", "en": "Vendor"},
"StorageModel": {"zh": "磁盘型号", "en": "Model"},
"StorageSerial": {"zh": "磁盘序列号", "en": "Serial"},
"StorageRemovable": {"zh": "磁盘可移除", "en": "Removable"},
"StorageSize": {"zh": "磁盘容量", "en": "Size"},
"BootTime": {"zh": "系统启动时间", "en": "Boot Time"},
"Uptime": {"zh": "系统运行时长", "en": "Uptime"},
"StartTime": {"zh": "系统启动用时", "en": "Startup Time"},
"User": {"zh": "用户名称", "en": "User"},
"UserName": {"zh": "用户昵称", "en": "Username"},
"UserUid": {"zh": "用户标识", "en": "UID"},
"UserGid": {"zh": "用户组标识", "en": "GID"},
"UserHomeDir": {"zh": "用户主目录", "en": "Home Dir"},
"UpdateList": {"zh": "更新列表", "en": "Update List"},
"UpdateDaemonStatus": {"zh": "更新服务", "en": "Update Daemon"},
}
各部分.条目的名称
var Language = GetLanguage() // 系统语言
var PartName = map[string]map[string]string{
"Product": {"zh": "设备", "en": "Product"},
"Board": {"zh": "主板", "en": "Board"},
"BIOS": {"zh": "BIOS", "en": "BIOS"},
"CPU": {"zh": "处理器", "en": "CPU"},
"GPU": {"zh": "显卡", "en": "GPU"},
"Memory": {"zh": "内存", "en": "Memory"},
"Swap": {"zh": "交换分区", "en": "Swap"},
"Disk": {"zh": "磁盘", "en": "Disk"},
"NIC": {"zh": "网卡", "en": "NIC"},
"OS": {"zh": "系统", "en": "OS"},
"Load": {"zh": "负载", "en": "Load"},
"Time": {"zh": "时间", "en": "Time"},
"User": {"zh": "用户", "en": "User"},
"Update": {"zh": "更新", "en": "Update"},
}
各部分的名称
var Platform = runtime.GOOS // 操作系统
var UserInfo, _ = GetUserInfoByName(UserName) // 用户信息
var UserName = func() string { if GetVariable("SUDO_USER") != "" { return GetVariable("SUDO_USER") } return GetVariable("USER") }()
用户名,当程序提权运行时,使用 SUDO_USER 变量获取提权前的用户名
Functions ¶
func CompareFile ¶ added in v1.1.6
CompareFile 并发比较两个文件是否相同
参数:
- file1Path: 文件1路径
- file2Path: 文件2路径
返回:
- 文件相同返回 true,出错或不同返回 false
func FileEmpty ¶ added in v1.1.6
FileEmpty 判断文件是否为空
- 无法判断文件夹
参数:
- filePath: 文件路径
返回:
- 文件为空返回 true,否则返回 false
func FolderEmpty ¶ added in v1.1.6
FolderEmpty 判断文件夹是否为空
- 包括隐藏文件
参数:
- dirPath: 文件夹路径
返回:
- 文件夹为空返回 true,否则返回 false
func FormatFloat ¶
FormatFloat 动态计算浮点数长度并输出合适的格式字符串
参数:
- value: 需要处理的浮点数
- precision: 期望的小数位数
返回:
- 格式化后的字符串
func GetCPUInfo ¶ added in v1.3.9
GetCPUInfo 获取 CPU 信息
参数:
- sysInfo: 总的系统信息
- dataUnit: 存储数据单位
返回:
- CPU 信息
func GetGPUInfo ¶ added in v1.3.9
func GetGPUInfo() map[string]interface{}
GetGPUInfo 获取显卡信息
返回:
- 显卡信息
func GetLanguage ¶ added in v1.2.5
func GetLanguage() string
GetLanguage 获取系统语言
返回:
- 系统语言,目前仅支持 zh 或 en
func GetLoadInfo ¶ added in v1.3.9
func GetLoadInfo() map[string]interface{}
GetLoadInfo 获取负载信息
返回:
- 系统负载信息
func GetMemoryInfo ¶ added in v1.3.9
GetMemoryInfo 获取内存信息
参数:
- dataUnit: 存储数据单位
- percentUnit: 百分比数据单位
返回:
- 内存信息
func GetNicInfo ¶ added in v1.3.9
func GetNicInfo() map[string]interface{}
GetNicInfo 获取网卡信息
返回:
- 网卡信息
func GetOSInfo ¶ added in v1.3.9
GetOSInfo 获取系统信息
参数:
- sysInfo: 总的系统信息 (System Info)
返回:
- 系统信息 (OS Info)
func GetStorageInfo ¶ added in v1.3.9
func GetStorageInfo() map[string]interface{}
GetStorageInfo 获取存储设备信息
返回:
- 存储设备信息
func GetTomlConfig ¶ added in v1.3.9
GetTomlConfig 读取 toml 配置文件
参数:
- filePath: toml 配置文件路径
返回:
- toml 配置树
- 错误信息
func GetUpdateInfo ¶ added in v1.3.9
GetUpdateInfo 读取更新信息记录文件
- 参数 line=0 时读取全部行
参数:
- filePath: 更新信息记录文件路径
- line: 读取指定行
返回:
- 更新信息
- 错误信息
func GetUserInfo ¶ added in v1.3.9
func GetUserInfo() map[string]interface{}
GetUserInfo 获取用户信息
返回:
- 用户信息
func Human ¶ added in v1.1.7
Human 存储数据转换为人类可读的格式
参数:
- size: 需要转换的存储数据
- initialUnit: 初始单位
返回:
- 转换后的数据
- 转换后的单位
func ReadFileCount ¶ added in v1.1.6
ReadFileCount 获取文件包含关键字的行的计数
参数:
- file: 文件路径
- key: 关键字
返回:
- 包含关键字的行的数量
func RunCommandGetResult ¶
RunCommandGetResult 运行命令并返回命令的输出
参数:
- command: 命令
- args: 命令参数
返回:
- 命令的输出
- 错误信息
func UnixTime2DayHourMinuteSecond ¶ added in v1.2.3
UnixTime2DayHourMinuteSecond Unix 时间戳转换为天、小时、分钟、秒
参数:
- totalSeconds: Unix 时间戳
返回:
- day: 天
- hour: 小时
- minute: 分钟
- second: 秒
func UnixTime2TimeString ¶ added in v1.2.3
UnixTime2TimeString uint64 格式的 Unix 时间戳转换为字符串格式
参数:
- timeStamp: Unix 时间戳
返回:
- 格式化的 Unix 时间戳字符串
func WriteTomlConfig ¶ added in v1.3.9
WriteTomlConfig 写入 toml 配置文件
参数:
- filePath: toml 配置文件路径
返回:
- 写入的字节数
- 错误信息
Types ¶
type Config ¶ added in v1.3.9
type Config struct { Genealogy GenealogyConfig `toml:"genealogy"` Main MainConfig `toml:"main"` }
用于转换 Toml 配置树的结构体
func LoadConfigToStruct ¶ added in v1.3.9
LoadConfigToStruct 将 Toml 配置树加载到结构体
参数:
- configTree: 解析 toml 配置文件得到的配置树
返回:
- 结构体
- 错误信息
type GenealogyConfig ¶ added in v1.3.9
type GenealogyConfig struct { Cpu CpuConfig `toml:"cpu"` Memory MemoryConfig `toml:"memory"` Update UpdateConfig `toml:"update"` }
type MainConfig ¶ added in v1.3.9
type MainConfig struct {
Colorful bool `toml:"colorful"`
}
type MemoryConfig ¶ added in v1.3.9
type UpdateConfig ¶ added in v1.3.9
type UpdateConfig struct {
RecordFile string `toml:"record_file"`
}