utils

package
v0.0.0-...-4ffdd69 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2026 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const DateFormat = "2006-01-02"
View Source
const MAXLENGTH = 80
View Source
const TimeFormat = "2006-01-02 15:04:05"

Variables

View Source
var (
	ErrCipherKey           = errors.New("the secret key is wrong and cannot be decrypted. Please check")
	ErrKeyLengthSixteen    = errors.New("a sixteen or twenty-four or thirty-two length secret key is required")
	ErrKeyLengthEight      = errors.New("a eight-length secret key is required")
	ErrKeyLengthTwentyFour = errors.New("a twenty-four-length secret key is required")
	ErrPaddingSize         = errors.New("padding size error please check the secret key or iv")
	ErrIvAes               = errors.New("a sixteen-length ivaes is required")
	ErrIvDes               = errors.New("a eight-length ivdes key is required")
	ErrRsaBits             = errors.New("bits 1024 or 2048")
)

Functions

func AesEcbDecrypt

func AesEcbDecrypt(plainText, secretKey []byte) (cipherText []byte, err error)

func AesEcbDecryptByBase64

func AesEcbDecryptByBase64(cipherTextBase64 string, key []byte) (plainText []byte, err error)

func AesEcbDecryptByHex

func AesEcbDecryptByHex(cipherTextHex string, key []byte) (plainText []byte, err error)

func AesEcbEncrypt

func AesEcbEncrypt(plainText, secretKey []byte) (cipherText []byte, err error)

func AesEcbEncryptBase64

func AesEcbEncryptBase64(plainText, key []byte) (cipherTextBase64 string, err error)

func AesEcbEncryptHex

func AesEcbEncryptHex(plainText, key []byte) (cipherTextHex string, err error)

func Bool2String

func Bool2String(val bool) string

func BytesToString

func BytesToString(b []byte) string

func CheckFileExist

func CheckFileExist(filename string) bool

func Contains

func Contains(s []int, n int) bool

Contains int in array

func CurrentDir

func CurrentDir(joinPath ...string) (string, error)

CurrentDir CurrentDir

func Download

func Download(title, fileUrl string) error

Download 下载文件

func DownloadAudio

func DownloadAudio(title, fileUrl string, opt ID3Options) error

DownloadAudio 下载mp3文件

func FileName

func FileName(name, ext string) string

FileName filter invalid string

func FilePath

func FilePath(name, ext string, escape bool) (string, error)

FilePath gen valid file path

func FileSize

func FileSize(filePath string) (int, bool, error)

FileSize return the file size of the specified path file

func Float2String

func Float2String(val float64) string

func FormatSeconds

func FormatSeconds(seconds int) string

FormatSeconds 格式化为 时:分:秒

func GetUrlExt

func GetUrlExt(rawURL string) (ext string, err error)

func Html2Md

func Html2Md(htmlStr string) (md string)

Html2Md html to markdown 将html转成markdown

func Html2Pdf

func Html2Pdf(fileName, title, content string) (err error)

func Int2String

func Int2String(val int) string

func Int64String

func Int64String(val int64) string

func LimitLength

func LimitLength(s string, length int) string

LimitLength cut string

func M3u8URLs

func M3u8URLs(uri string) (urls []string, err error)

M3u8URLs get all ts urls from m3u8 url

func MD5str

func MD5str(s string) string

func MarshalJSON

func MarshalJSON(v interface{}) ([]byte, error)

MarshalJSON 将 v json序列化

func Md5

func Md5(text string) string

func MergeAudio

func MergeAudio(paths []string, mergedFilePath string) error

MergeAudio merge audio

func MergeAudioAndVideo

func MergeAudioAndVideo(paths []string, mergedFilePath string) error

MergeAudioAndVideo merge audio and video

func MergeToMP4

func MergeToMP4(paths []string, mergedFilePath string, filename string) error

MergeToMP4 merges video parts to an MP4 file.

func Mkdir

func Mkdir(elem ...string) (string, error)

Mkdir mkdir path

func PKCS5Padding

func PKCS5Padding(plainText []byte, blockSize int) []byte

func PKCS5UnPadding

func PKCS5UnPadding(plainText []byte, blockSize int) ([]byte, error)

func ResolveURL

func ResolveURL(u *url.URL, p string) string

ResolveURL parse url

func SaveFile

func SaveFile(title, content string) error

SaveFile 保存文件

func String2Int

func String2Int(val string) int

func StringToBytes

func StringToBytes(s string) []byte

func TimeCost

func TimeCost(start time.Time)

func Unix2String

func Unix2String(stamp int64) string

Unix2String 时间戳[转换为]字符串 eg:(2019-09-09 09:09:09)

func UnixMilli2DateString

func UnixMilli2DateString(stamp int64) string

func UnixMilli2String

func UnixMilli2String(stamp int64) string

UnixMilli2String 时间戳[转换为]字符串 eg:(2019-09-09 09:09:09)

func UnmarshalJSON

func UnmarshalJSON(data []byte, v interface{}) error

UnmarshalJSON 将 data 中的 json 格式的数据, 解析到 v

func UnmarshalReader

func UnmarshalReader(r io.Reader, v interface{}) error

UnmarshalReader 将 r 中的 json 格式的数据, 解析到 v

func WriteFileWithTrunc

func WriteFileWithTrunc(filename, content string) (err error)

Types

type ID3Options

type ID3Options struct {
	Title  string // 标题
	Artist string // 参与创作的艺术家
	Album  string // 唱片集
	Cover  []byte // 封面
	Year   string
	Genre  string // 流派
}

type PdfOption

type PdfOption struct {
	FileName  string
	CoverPath string
	PageSize  string
	Toc       bool
	Title     string
	Author    string
	Subject   string
	Keywords  string
}

func (*PdfOption) GenPdf

func (p *PdfOption) GenPdf(buf *bytes.Buffer) (err error)

type ValidUTF8Reader

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

ValidUTF8Reader implements a Reader which reads only bytes that constitute valid UTF-8

func NewValidUTF8Reader

func NewValidUTF8Reader(rd io.Reader) ValidUTF8Reader

NewValidUTF8Reader constructs a new ValidUTF8Reader that wraps an existing io.Reader

func (ValidUTF8Reader) Read

func (rd ValidUTF8Reader) Read(b []byte) (n int, err error)

Function Read reads bytes in the byte array b. n is the number of bytes read.

Jump to

Keyboard shortcuts

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