utils

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	B int64 = 1 << (10 * iota)
	KB
	MB
	GB
	TB
	PB
)

Variables

This section is empty.

Functions

func CheckPath

func CheckPath(path string) (exists bool, isDir bool, err error)

CheckPath 检查路径是否存在,并返回是否为目录, 支持~路径检测.

func DetectContentType

func DetectContentType(data []byte, ext string) string

func DirExists

func DirExists(dirPath string) bool

DirExists 判断目录是否存在.

func ExpandTilde added in v0.1.3

func ExpandTilde(path string) (string, error)

ExpandTilde 扩展波浪号路径.

func FileExists

func FileExists(path string) bool

FileExists 判断文件是否存在.

func Filename added in v0.0.4

func Filename(path string, new ...string) string

Filename 清理文件名中的非法字符.

func GenerateChainId added in v0.4.0

func GenerateChainId(deviceId string) string

GenerateChainId 生成ChainId 用于web login 规则: "{version}_{s_device_id}_{platform}_{action}_{timestamp}" .

func GenerateDeviceId added in v0.4.0

func GenerateDeviceId(isLong ...bool) string

GenerateDeviceId 生成设备ID 目前发现有两种格式设备id 格式1: 52位十六进制字符串 (大写) 例如: D82036205567D95288D26BCF3797FE22D8A7634320474768C7ED 格式2: 两个UUID拼接而成, 中间用|分隔, UUID格式为8-4-4-4-12的十六进制字符串 (大写) 例如: 7A8EB581-E60B-5230-BB5B-E6DAB1FBFA62|5FD718A3-0602-4389-B612-EBEFAA7F108B.

func GenerateWNMCID added in v0.4.0

func GenerateWNMCID() string

GenerateWNMCID 生成WNMCID 生成规则: 6位随机小写字母 + 当前时间戳(毫秒) + 默认抓取版本号 + 0 例如: "abcdef.1633557080686.01.0" 作用: 貌似是网易云音乐的抓取标识,或者用于爬虫标识等作用.

func IsFile

func IsFile(path string) bool

IsFile 判断是否为文件.

func IsGzipHeader added in v0.1.0

func IsGzipHeader(data []byte) bool

IsGzipHeader 判断字节数据是否以 Gzip 文件头开头 Gzip 文件头特征:前 2 个字节为 0x1F 0x8B,第三个字节为压缩方法(通常 0x08 表示 DEFLATE).

func IsMusicExt

func IsMusicExt(ext string) bool

func IsUnique

func IsUnique[T comparable](arr []T) bool

func MD5Hex

func MD5Hex(data []byte) (string, error)

func MkdirIfNotExist

func MkdirIfNotExist(path string, perm os.FileMode) error

func ParseBytes

func ParseBytes(input string) (int64, error)

ParseBytes 将输入字符串转换为字节数.

func SplitSlice

func SplitSlice[T any](input []T, chunkSize int) ([][]T, error)

func Ternary

func Ternary[T any](condition bool, trueVal, falseVal T) T

Ternary is a generic function that mimics a ternary expression.

func TimeUntilMidnight

func TimeUntilMidnight(timeZone string) (time.Duration, error)

TimeUntilMidnight 计算当前时间到明天零点的时间差.

Types

This section is empty.

Jump to

Keyboard shortcuts

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