utils

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2025 License: MIT Imports: 11 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 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