common

package
v0.63.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2024 License: AGPL-3.0 Imports: 36 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 Logger *slog.Logger
View Source
var ResendClient *resend.Client
View Source
var TagRe = regexp.MustCompile(`(?:^|[\p{Zs}\s.,!?(){}[\]<>\"\',。!?():;、])#([\p{L}\d_]+)`)

Functions

func ApplyPathRule

func ApplyPathRule(path string) string

func CompressImageByFFmpeg

func CompressImageByFFmpeg(inputPath, outputPath string, maxEdgeLength int) error

使用 ffmpeg 压缩图片

func CompressImageForTelegramByFFmpegFromBytes added in v0.60.0

func CompressImageForTelegramByFFmpegFromBytes(input []byte) ([]byte, error)

func CompressImageToJPEG

func CompressImageToJPEG(input []byte, maxEdgeLength, maxFileSize uint) ([]byte, error)

func DownloadWithCache

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

func EscapeFileName

func EscapeFileName(str 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 GetBodyReader added in v0.60.0

func GetBodyReader(ctx context.Context, url string, client *req.Client) (io.ReadCloser, error)

func GetImageBlurScore deprecated

func GetImageBlurScore(img image.Image) (float64, error)

Deprecated: sometimes inaccurate

func GetImageBlurScoreFromReader deprecated added in v0.60.0

func GetImageBlurScoreFromReader(r io.Reader) (float64, error)

Deprecated: sometimes inaccurate

func GetImagePhash

func GetImagePhash(img image.Image) (string, error)

func GetImagePhashFromReader added in v0.60.0

func GetImagePhashFromReader(r io.Reader) (string, error)

func GetImageSize

func GetImageSize(img image.Image) (int, int, error)

func GetImageSizeFromReader added in v0.60.0

func GetImageSizeFromReader(r io.Reader) (int, int, error)

func GetReqCachedFile

func GetReqCachedFile(url string) ([]byte, error)

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 MD5Hash added in v0.61.0

func MD5Hash(data string) string

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

ResizeImage resizes an image to the specified width and height.

It use golang.org/x/image/draw and CatmullRom interpolation. (Slow but high quality, and cost many memory)

func RmFileAfter added in v0.60.0

func RmFileAfter(path string, td time.Duration)

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