common

package
v0.37.1 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2024 License: GPL-3.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Version   string = "dev"
	BuildTime string = "Unknown"
	Commit    string = "Unknown"
)
View Source
var Client *req.Client
View Source
var ResendClient *resend.Client

Functions

func ApplyPathRule

func ApplyPathRule(path string) string

func CompressImageByFFmpeg

func CompressImageByFFmpeg(inputPath, outputPath string, maxEdgeLength uint, quality uint) error

使用 ffmpeg 压缩图片

func CompressImageToJPEG

func CompressImageToJPEG(input []byte, maxSizeMB, maxEdgeLength uint, cacheKey string) ([]byte, error)

func DownloadWithCache

func DownloadWithCache(ctx context.Context, url string, client *req.Client) ([]byte, error)

func EscapeFileName

func EscapeFileName(fileName string) string

func EscapeHTML

func EscapeHTML(text string) string

func EscapeMarkdown

func EscapeMarkdown(text string) string

func ExtractTagsFromText

func ExtractTagsFromText(text string) []string

func FileExists

func FileExists(path string) bool

func GenerateRandomString

func GenerateRandomString(length int, charset ...string) string

func GetImageBlurScore

func GetImageBlurScore(b []byte) (float64, error)

func GetImagePhash

func GetImagePhash(b []byte) (string, error)

func GetImageSize

func GetImageSize(b []byte) (int, int, error)

宽高

func GetReqCachedFile

func GetReqCachedFile(path string) []byte

func GinBindError

func GinBindError(ctx *gin.Context, err error)

func GinErrorResponse

func GinErrorResponse(ctx *gin.Context, err error, status int, message string)

func Init

func Init()

func MkCache

func MkCache(path string, data []byte, td time.Duration)

func MkFile

func MkFile(path string, data []byte) error

创建文件, 自动创建目录

func ParseStringTo2DArray

func ParseStringTo2DArray(str, sep, sep2 string) [][]string

解析字符串为二维数组, 如果以字符串以引号包裹, 则无视分隔符

ParseStringTo2DArray("1,2,3;4,5,6", ",", ";") => [][]string{{"1", "2", "3"}, {"4", "5", "6"}}

ParseStringTo2DArray("1,2,3;\"4,5,6\"", ",", ";") => [][]string{{"1", "2", "3"}, {"4,5,6"}}

func PurgeFile

func PurgeFile(path string) error

删除文件, 并清理空目录. 如果文件不存在则返回 nil

func PurgeFileAfter

func PurgeFileAfter(path string, td time.Duration)

在指定时间后删除和清理文件 (定时器)

func RemoveEmptyDirectories

func RemoveEmptyDirectories(dirPath string) error

递归删除空目录

func ResizeImage

func ResizeImage(img image.Image, width, height uint) image.Image

Types

type RestfulCommonResponse

type RestfulCommonResponse[T any] struct {
	Status  int    `json:"status"`
	Message string `json:"message"`
	Data    T      `json:"data"`
}

Jump to

Keyboard shortcuts

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