utils

package
v0.0.0-...-d9344ac Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2025 License: Apache-2.0 Imports: 31 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AutoConvert

func AutoConvert(s string) interface{}

func BackupPath

func BackupPath(src string) string

func CheckIfFileExistsIgnoringExt

func CheckIfFileExistsIgnoringExt(dir, filenameWithoutExt string) (bool, error)

CheckIfFileExistsIgnoringExt 检查指定目录下是否存在给定名称的文件,忽略文件扩展名。

func ContainsInSlice

func ContainsInSlice[T any](slice []T, elem T) bool

func ExecuteCommandToFile

func ExecuteCommandToFile(command string, outputFilePath string, args ...string) error

func ExecuteCommandToNull

func ExecuteCommandToNull(command string, dirPath string, args ...string) error

func ExtractExecutable

func ExtractExecutable(archivePath, dir string) string

func ExtractLastPathSegment

func ExtractLastPathSegment(inputURL string) string

func GetBody

func GetBody(body io.Reader) string

func GetCurrentExecutablePath

func GetCurrentExecutablePath() string

func GetEnv

func GetEnv(key string) string

func GetFilenameWithoutExt

func GetFilenameWithoutExt(path string) string

func GetResourceFromPageNum

func GetResourceFromPageNum[T any](pageNum, numPerPage int, data []T) []T

func HttpGet

func HttpGet(url string) string

func HttpGetDownload

func HttpGetDownload(url string, dir string, name string) string

func HttpGetDownloadWithProgress

func HttpGetDownloadWithProgress(url string, dir string, name string) string

HttpGetDownloadWithProgress 下载文件到指定目录,支持进度条

func HttpPost

func HttpPost(url string, contentType string, body io.Reader) string

func IsRegularFile

func IsRegularFile(path string) bool

func JsonDump

func JsonDump(value interface{}) string

func JsonLoad

func JsonLoad(date []byte) interface{}

func NewHTTPClientWithHTTPProxy

func NewHTTPClientWithHTTPProxy() *http.Client

NewHTTPClientWithHTTPProxy 创建一个使用 HTTP/HTTPS 代理的 http.Client proxyURLStr 格式示例:

func NewHTTPClientWithSocket5Proxy

func NewHTTPClientWithSocket5Proxy() *http.Client

func Paginate

func Paginate[T any](data []T, pageSize int) map[int][]T

Paginate 分页函数:将任意类型切片分页并转为 map[int][]T

func PrintSliceAsTable

func PrintSliceAsTable[T any](title string, data []T)

PrintSliceAsTable 打印结构体数组为表格形式

func RemoveHTMLTags

func RemoveHTMLTags(html string) string

func SortByField

func SortByField[T any](data []T, fieldName string)

func StripExt

func StripExt(filename string) string

stripExt 去除文件名中的扩展名。

Types

type BarTask

type BarTask struct {
	MaxWorker    int
	PrintLineNum int

	TaskStatusArray []*taskStatus
	Refresh         time.Duration
	// contains filtered or unexported fields
}

func NewBarTask

func NewBarTask(maxWorker int) *BarTask

func (*BarTask) Add

func (bar *BarTask) Add(fun func(), taskName string)

func (*BarTask) Finish

func (bar *BarTask) Finish()

type Cache

type Cache struct {
	BasePath string
}

Cache 结构体定义

func NewCache

func NewCache(basePath string) (*Cache, error)

NewCache 创建一个新的缓存实例,并确保目标目录存在

func (*Cache) Clean

func (c *Cache) Clean(key string) error

Clean 删除指定 key 的缓存文件

func (*Cache) CleanAll

func (c *Cache) CleanAll() error

CleanAll 清除所有缓存文件

func (*Cache) Get

func (c *Cache) Get(key string, data interface{}) error

Get 根据 key 读取数据

func (*Cache) Set

func (c *Cache) Set(key string, data interface{}) error

Set 写入键值对到文件中

type GoroutinePool

type GoroutinePool struct {
	// contains filtered or unexported fields
}

func NewGoroutinePool

func NewGoroutinePool(maxWorkers int, expiryDuration time.Duration) (*GoroutinePool, error)

NewGoroutinePool 创建一个新的GoroutinePool实例

func (*GoroutinePool) Release

func (gp *GoroutinePool) Release()

Release 释放资源

func (*GoroutinePool) Submit

func (gp *GoroutinePool) Submit(task func()) error

Submit 提交一个任务到池中,并增加WaitGroup计数

func (*GoroutinePool) Wait

func (gp *GoroutinePool) Wait()

Wait 等待所有任务完成

Jump to

Keyboard shortcuts

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