general

package
v0.6.9 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: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Name    string = "Rolling"                 // 程序名
	Version string = "v0.6.9"                  // 程序版本
	Project string = "github.com/yhyj/rolling" // 项目地址
)

Variables

View Source
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 文本
)
View Source
var (
	GitCommitHash string = "Unknown" // Git 提交 Hash
	BuildTime     string = "Unknown" // 编译时间
	BuildBy       string = "Unknown" // 编译者
)
View Source
var Arch = runtime.GOARCH // 系统架构
View Source
var Platform = runtime.GOOS // 操作系统
View Source
var UserInfo, _ = GetUserInfoByName(UserName) // 用户信息
View Source
var UserName = func() string {
	if GetVariable("SUDO_USER") != "" {
		return GetVariable("SUDO_USER")
	}
	return GetVariable("USER")
}()

用户名,当程序提权运行时,使用 SUDO_USER 变量获取提权前的用户名

Functions

func CompareFile added in v0.5.4

func CompareFile(file1Path string, file2Path string) (bool, error)

CompareFile 并发比较两个文件是否相同

参数:

  • file1Path: 文件1路径
  • file2Path: 文件2路径

返回:

  • 文件相同返回 true,出错或不同返回 false

func CreateDir added in v0.5.4

func CreateDir(dirPath string) error

CreateDir 创建文件夹

参数:

  • dirPath: 文件夹路径

返回:

  • 错误信息

func CreateFile added in v0.5.4

func CreateFile(filePath string) error

CreateFile 创建文件,包括其父目录

参数:

  • filePath: 文件路径

返回:

  • 错误信息

func DeleteFile added in v0.5.4

func DeleteFile(filePath string) error

DeleteFile 删除文件

参数:

  • filePath: 文件路径

返回:

  • 错误信息

func FileEmpty added in v0.5.4

func FileEmpty(filePath string) bool

FileEmpty 判断文件是否为空

  • 无法判断文件夹

参数:

  • filePath: 文件路径

返回:

  • 文件为空返回 true,否则返回 false

func FileExist added in v0.5.4

func FileExist(filePath string) bool

FileExist 判断文件是否存在

参数:

  • filePath: 文件路径

返回:

  • 文件存在返回 true,否则返回 false

func FindFakeMaxLength added in v0.6.9

func FindFakeMaxLength(numbers []interface{}) int

FindFakeMaxLength 计算多个 int, float 类型数字直接转为 string 后最长者长度

参数:

  • numbers: 数字列表

返回:

  • 最长长度

func FolderEmpty added in v0.5.4

func FolderEmpty(dirPath string) bool

FolderEmpty 判断文件夹是否为空

  • 包括隐藏文件

参数:

  • dirPath: 文件夹路径

返回:

  • 文件夹为空返回 true,否则返回 false

func GetAbsPath added in v0.5.4

func GetAbsPath(filePath string) string

GetAbsPath 获取指定文件的绝对路径

参数:

  • filePath: 文件路径

返回:

  • 文件的绝对路径

func GetCurrentUserInfo added in v0.5.4

func GetCurrentUserInfo() (*user.User, error)

GetCurrentUserInfo 获取当前用户信息

返回:

  • 用户信息
  • 错误信息

func GetHostname added in v0.5.4

func GetHostname() string

GetHostname 获取系统 HOSTNAME

返回:

  • HOSTNAME 或空字符串

func GetSystemUpdateCount added in v0.6.8

func GetSystemUpdateCount(file string) (int, error)

GetSystemUpdateCount 获取系统更新次数

参数:

  • file: 记录系统更新信息的文件的路径

返回:

  • 系统更新次数
  • 错误信息

func GetUserInfoById added in v0.5.4

func GetUserInfoById(userId int) (*user.User, error)

GetUserInfoById 根据 ID 获取用户信息

参数:

  • userId: 用户 ID

返回:

  • 用户信息
  • 错误信息

func GetUserInfoByName added in v0.5.4

func GetUserInfoByName(userName string) (*user.User, error)

GetUserInfoByName 根据用户名获取用户信息

参数:

  • userName: 用户名

返回:

  • 用户信息
  • 错误信息

func GetVariable added in v0.5.4

func GetVariable(key string) string

GetVariable 获取环境变量

参数:

  • key: 变量名

返回:

  • 变量值

func GoToDir added in v0.5.4

func GoToDir(dirPath string) error

GoToDir 进到指定文件夹

参数:

  • dirPath: 文件夹路径

返回:

  • 错误信息

func ProgramInfo

func ProgramInfo() map[string]string

ProgramInfo 返回程序信息

返回:

  • 程序信息

func ReadFileCount

func ReadFileCount(file, key string) int

ReadFileCount 获取文件包含关键字的行的计数

参数:

  • file: 文件路径
  • key: 关键字

返回:

  • 包含关键字的行的数量

func ReadFileKey

func ReadFileKey(file, key string) string

ReadFileKey 读取文件包含关键字的行

参数:

  • file: 文件路径
  • key: 关键字

返回:

  • 包含关键字的行的内容

func ReadFileLine

func ReadFileLine(file string, line int) string

ReadFileLine 读取文件指定行

参数:

  • file: 文件路径
  • line: 行号

返回:

  • 指定行的内容

func RoundFloat32 added in v0.6.9

func RoundFloat32(number float32, precision int) float32

RoundFloat32 返回保留指定位小数的 float32 类型数字

参数:

  • number: 数字,类型为 float32

返回:

  • 保留指定位小数的数字

func RunCommand

func RunCommand(command string, args []string) error

RunCommand 运行命令不返回命令的输出

参数:

  • command: 命令
  • args: 命令参数

返回:

  • 错误信息

func RunCommandGetResult

func RunCommandGetResult(command string, args []string) (string, error)

RunCommandGetResult 运行命令并返回命令的输出

参数:

  • command: 命令
  • args: 命令参数

返回:

  • 命令的输出
  • 错误信息

func SetVariable added in v0.5.4

func SetVariable(key, value string) error

SetVariable 设置环境变量

参数:

  • key: 变量名
  • value: 变量值

返回:

  • 错误信息

func WriteFile added in v0.5.4

func WriteFile(filePath string, content string) error

WriteFile 写入内容到文件

参数:

  • filePath: 文件路径
  • content: 内容

返回:

  • 错误信息

Types

This section is empty.

Jump to

Keyboard shortcuts

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