Documentation
¶
Overview ¶
@author fenglei
@author fenglei
@author fenglei
@author fenglei
@author fenglei
@author fenglei
@author fenglei
@author fenglei
@author fenglei
@author fenglei
Index ¶
- func AsyncExecute(tasks []*AsyncTask, poolSize int) *garray.Array
- func AsyncExecuteFunc[T any, R any](params []T, fn func(T) R, poolSize int) []R
- func AsyncRun(funcs []func(), poolSize int)
- func CompressDirTarGz(filePath, tarDirPath string) error
- func CompressFileTarGz(dirPath, targetFile string) error
- func ContentReplace(path string, oldStr, newStr string) error
- func Decompose(sourceFile, targetPath string) error
- func DelFileOrDir(dir string) error
- func DelFileOrDirWithParent(path string) error
- func DeleteDirContent(dir string) error
- func DirSize(dirPath string) (int64, error)
- func DirSizeMb(path string) (int64, error)
- func ExternalIP() (string, error)
- func ExtractArchiveAuto(archiveFile, destDir string) error
- func FileMainName(path string) string
- func FileMd5(filePath string) string
- func GetEnv() string
- func GetFileExtensionByType(fileType FileType) string
- func IsCompressedFile(filePath string) bool
- func IsDevEnv() bool
- func IsIDCAddress() (bool, error)
- func NowTime() time.Time
- func SafeGo(fn func(), handler ...PanicHandler)
- func SafeGoWithArg[T any](arg T, fn func(T), handler ...PanicHandler)
- func SetDefaultPanicHandler(handler PanicHandler)
- func SimpleUID() string
- func StrPrefixRemove(str, prefix string) string
- func StrSuffixRemove(str, suffix string) string
- func TrackTime(n time.Time, name string)
- func UUID() string
- func XID() string
- type AsyncTask
- type FileType
- type PanicHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AsyncExecute ¶ added in v0.2.42
AsyncExecute 使用协程池批量执行异步任务 tasks: 任务列表 poolSize: 协程池大小,<=0 时使用任务数量作为池大小 返回: 所有任务执行结果的数组(顺序不保证与输入一致)
func AsyncExecuteFunc ¶ added in v0.2.42
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
CompressionTarGz 将指定文件压缩成 tar.gz 格式 filePath: 要压缩的文件路径 tarDirPath: 压缩后的目标文件路径
func CompressFileTarGz ¶ added in v0.1.19
CompressDirectory 压缩整个目录到tar.gz文件
func ContentReplace ¶ added in v0.1.18
文件内容替换
func DelFileOrDir ¶ added in v0.1.24
DeleteDir 删除指定目录及其中的所有内容(文件和子目录) 如果目录不存在,返回 nil(视为删除成功) 如果目录存在但无法删除,返回错误
func DelFileOrDirWithParent ¶ added in v0.1.34
DelFileOrDirWithParent 删除指定文件或目录,如果父目录变空则同时删除父目录 这个函数会先删除指定的文件或目录,然后检查其父目录是否为空 如果父目录为空,则也会删除父目录
func DeleteDirContent ¶ added in v0.1.18
DeleteDirContent 删除目录中的所有内容,但保留目录本身 如果目录不存在,返回错误
func ExtractArchiveAuto ¶ added in v0.1.26
ExtractArchiveAuto 自动检测文件类型并解压 支持 .tar, .tar.gz, .tgz 格式
func GetFileExtensionByType ¶ added in v0.1.26
GetFileExtensionByType 根据文件类型返回对应的扩展名
func IsCompressedFile ¶ added in v0.1.26
IsCompressedFile 检查文件是否为压缩文件
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处理函数
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
GetFileCompressType 获取文件的压缩类型 通过检查文件头部的魔数(特征字节)来确定文件类型
type PanicHandler ¶ added in v0.2.42
type PanicHandler func(r interface{}, stack []byte)
PanicHandler panic处理函数类型