xxutil

package
v0.2.47 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: MulanPSL-2.0 Imports: 27 Imported by: 0

Documentation

Overview

@author fenglei

@author fenglei

@author fenglei

@author fenglei

@author fenglei

@author fenglei

@author fenglei

@author fenglei

@author fenglei

@author fenglei

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsyncExecute added in v0.2.42

func AsyncExecute(tasks []*AsyncTask, poolSize int) *garray.Array

AsyncExecute 使用协程池批量执行异步任务 tasks: 任务列表 poolSize: 协程池大小,<=0 时使用任务数量作为池大小 返回: 所有任务执行结果的数组(顺序不保证与输入一致)

func AsyncExecuteFunc added in v0.2.42

func AsyncExecuteFunc[T any, R any](params []T, fn func(T) R, poolSize int) []R

AsyncExecuteFunc 使用协程池批量执行同一个函数,传入不同参数 params: 参数列表 fn: 执行函数 poolSize: 协程池大小,<=0 时使用参数数量作为池大小 返回: 所有任务执行结果的数组(顺序不保证与输入一致)

func AsyncRun added in v0.2.42

func AsyncRun(funcs []func(), poolSize int)

AsyncRun 使用协程池执行一组无返回值的函数 funcs: 要执行的函数列表 poolSize: 协程池大小,<=0 时使用函数数量作为池大小

func CompressDirTarGz added in v0.1.19

func CompressDirTarGz(filePath, tarDirPath string) error

CompressionTarGz 将指定文件压缩成 tar.gz 格式 filePath: 要压缩的文件路径 tarDirPath: 压缩后的目标文件路径

func CompressFileTarGz added in v0.1.19

func CompressFileTarGz(dirPath, targetFile string) error

CompressDirectory 压缩整个目录到tar.gz文件

func ContentReplace added in v0.1.18

func ContentReplace(path string, oldStr, newStr string) error

文件内容替换

func Decompose added in v0.1.19

func Decompose(sourceFile, targetPath string) error

Decompose 解压缩文件到指定目录 sourceFile: 要解压的文件路径 targetPath: 解压的目标目录

func DelFileOrDir added in v0.1.24

func DelFileOrDir(dir string) error

DeleteDir 删除指定目录及其中的所有内容(文件和子目录) 如果目录不存在,返回 nil(视为删除成功) 如果目录存在但无法删除,返回错误

func DelFileOrDirWithParent added in v0.1.34

func DelFileOrDirWithParent(path string) error

DelFileOrDirWithParent 删除指定文件或目录,如果父目录变空则同时删除父目录 这个函数会先删除指定的文件或目录,然后检查其父目录是否为空 如果父目录为空,则也会删除父目录

func DeleteDirContent added in v0.1.18

func DeleteDirContent(dir string) error

DeleteDirContent 删除目录中的所有内容,但保留目录本身 如果目录不存在,返回错误

func DirSize added in v0.1.18

func DirSize(dirPath string) (int64, error)

获取目录的大小

func DirSizeMb added in v0.1.18

func DirSizeMb(path string) (int64, error)

获取目录的大小Mb

func ExternalIP

func ExternalIP() (string, error)

获取内网IP地址

func ExtractArchiveAuto added in v0.1.26

func ExtractArchiveAuto(archiveFile, destDir string) error

ExtractArchiveAuto 自动检测文件类型并解压 支持 .tar, .tar.gz, .tgz 格式

func FileMainName

func FileMainName(path string) string

只获取文件名,不含后辍

func FileMd5

func FileMd5(filePath string) string

获取文件的Md5

func GetEnv added in v0.1.40

func GetEnv() string

获取运行环境配置文件内容

func GetFileExtensionByType added in v0.1.26

func GetFileExtensionByType(fileType FileType) string

GetFileExtensionByType 根据文件类型返回对应的扩展名

func IsCompressedFile added in v0.1.26

func IsCompressedFile(filePath string) bool

IsCompressedFile 检查文件是否为压缩文件

func IsDevEnv added in v0.1.5

func IsDevEnv() bool

获取运行环境配置文件是否为dev

func IsIDCAddress

func IsIDCAddress() (bool, error)

是否是IDC的地址

func NowTime added in v0.1.39

func NowTime() time.Time

北京当前时间

func SafeGo added in v0.2.42

func SafeGo(fn func(), handler ...PanicHandler)

SafeGo 安全地启动一个goroutine,自动捕获panic fn: 要执行的函数 handler: 可选的panic处理函数,不传则使用默认处理函数

func SafeGoWithArg added in v0.2.42

func SafeGoWithArg[T any](arg T, fn func(T), handler ...PanicHandler)

SafeGoWithArg 安全地启动一个带参数的goroutine 用于避免闭包捕获循环变量的问题

func SetDefaultPanicHandler added in v0.2.42

func SetDefaultPanicHandler(handler PanicHandler)

SetDefaultPanicHandler 设置全局默认的panic处理函数

func SimpleUID added in v0.1.38

func SimpleUID() string

UID

func StrPrefixRemove added in v0.1.26

func StrPrefixRemove(str, prefix string) string

移除字符串指定的头

func StrSuffixRemove added in v0.1.26

func StrSuffixRemove(str, suffix string) string

移除字符串指定的尾

func TrackTime added in v0.1.8

func TrackTime(n time.Time, name string)

添加时间跟踪函数

func UUID

func UUID() string

uuid 32位

func XID

func XID() string

20位可解析日期的ID

Types

type AsyncTask added in v0.2.42

type AsyncTask struct {
	// 任务执行函数
	Func func() interface{}
}

AsyncTask 异步任务定义

type FileType added in v0.1.26

type FileType string

FileType 表示文件的压缩类型

const (
	TypeUnknown  FileType = "unknown" // 未知类型
	TypeGzip     FileType = "gzip"    // Gzip 格式
	TypeTarGz    FileType = "tar.gz"  // Tar+Gzip 格式
	TypeZip      FileType = "zip"     // ZIP 格式
	TypeTar      FileType = "tar"     // Tar 格式
	TypeRar      FileType = "rar"     // RAR 格式
	Type7z       FileType = "7z"      // 7z 格式
	TypeBzip2    FileType = "bzip2"   // BZip2 格式
	TypeTarBzip2 FileType = "tar.bz2" // Tar+BZip2 格式
	TypeXz       FileType = "xz"      // XZ 格式
	TypeTarXz    FileType = "tar.xz"  // Tar+XZ 格式
)

func GetFileCompressType added in v0.1.26

func GetFileCompressType(filePath string) (FileType, error)

GetFileCompressType 获取文件的压缩类型 通过检查文件头部的魔数(特征字节)来确定文件类型

type PanicHandler added in v0.2.42

type PanicHandler func(r interface{}, stack []byte)

PanicHandler panic处理函数类型

Jump to

Keyboard shortcuts

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