goutils

package module
v1.1.11 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: LGPL-3.0 Imports: 39 Imported by: 0

README

go-utils


Add common Golang utility classes or self-developed components, and then make some simple encapsulations according to the usage methods.

Below are some of the included components or self-developed components:

- Gorm database-related utilities
- String/crypt handling methods
- Number/decimal handling methods
- Video processing program
- Date handling
- Google Translate (including batch translation interface)
- HTTP helpers
- Console helpers
- Atomic locks
- Image processing
- Logging
- Snowflake ID
- Cryptocurrency
- Cloud service interfaces
- File processing

go-utils


添加常用的golang 工具类或自行开发的组件,然后根据使用方法做了一些简单封装

以下是包含的部分组件或自行开发的组件:

- gorm 数据库相关
- string/crypt 处理方法
- number/decimal 处理方法
- 视频处理程序
- 日期 处理
- 谷歌翻译(包含大批量翻译接口)
- http helpers
- console helpers
- 原子锁
- 图片处理
- 日志处理
- 雪花id
- 加密货币
- 云服务接口
- 文件处理

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DownImage

func DownImage(url, name, savePath string) (string, error)

func MergeStructData added in v1.0.1

func MergeStructData(existing, newData interface{}) interface{}

MergeStructData 使用反射来合并两个struct 反射影响高性能

Types

type AesUtils

type AesUtils struct{}

func NewAesUtils

func NewAesUtils() *AesUtils

func (*AesUtils) EncryptAES

func (a *AesUtils) EncryptAES(key, plaintext []byte, ivString string) (string, error)

func (*AesUtils) PKCS7Padding

func (a *AesUtils) PKCS7Padding(ciphertext []byte, blockSize int) []byte

PKCS7Padding adds padding to the original text to fit the block size

type ConsoleUtils

type ConsoleUtils struct{}

func NewConsoleUtils

func NewConsoleUtils() *ConsoleUtils

func (*ConsoleUtils) Black

func (c *ConsoleUtils) Black(txt string)

func (*ConsoleUtils) BlackBold

func (c *ConsoleUtils) BlackBold(txt string)

func (*ConsoleUtils) Green

func (c *ConsoleUtils) Green(txt string)

func (*ConsoleUtils) Red

func (c *ConsoleUtils) Red(txt string)

type CryptoUtils

type CryptoUtils struct{}

func NewCryptoUtils

func NewCryptoUtils() *CryptoUtils

func (*CryptoUtils) DecryptStr added in v1.1.0

func (u *CryptoUtils) DecryptStr(text string, pass string) (string, error)

func (*CryptoUtils) EncryptStr added in v1.1.0

func (u *CryptoUtils) EncryptStr(text string, pass string) (string, error)

type FFMpegUtils

type FFMpegUtils struct{}

func NewFFMpegUtils

func NewFFMpegUtils() *FFMpegUtils

func (*FFMpegUtils) H264ToHls

func (f *FFMpegUtils) H264ToHls(filePath string, tsDir string, idxFilePath string, tsSeconds uint8) error

func (*FFMpegUtils) ToHlsNonH264

func (f *FFMpegUtils) ToHlsNonH264(filePath string, tsDir string, idxFilePath string, tsSeconds uint8) error

type FFProbeUtils

type FFProbeUtils struct{}

func NewFFProbeUtils

func NewFFProbeUtils() *FFProbeUtils

func (*FFProbeUtils) GetBitRates

func (f *FFProbeUtils) GetBitRates(filePath string) int

func (*FFProbeUtils) GetCodecNames

func (f *FFProbeUtils) GetCodecNames(filePath string) []string

func (*FFProbeUtils) GetDuration

func (f *FFProbeUtils) GetDuration(filePath string) int64

func (*FFProbeUtils) GetFormatName

func (f *FFProbeUtils) GetFormatName(filePath string) string

func (*FFProbeUtils) GetResolution

func (f *FFProbeUtils) GetResolution(filePath string) string

func (*FFProbeUtils) GetVideoDetails

func (f *FFProbeUtils) GetVideoDetails(filePath string) string

func (*FFProbeUtils) IsH264

func (f *FFProbeUtils) IsH264(filePath string) bool

func (*FFProbeUtils) IsValidExt

func (f *FFProbeUtils) IsValidExt(filePath, ext string) bool

type GoogleTranslationUtils

type GoogleTranslationUtils struct{}

func NewGoogleTranslationUtils

func NewGoogleTranslationUtils() *GoogleTranslationUtils

func (*GoogleTranslationUtils) GoogleDetectLang

func (g *GoogleTranslationUtils) GoogleDetectLang(text string)

func (*GoogleTranslationUtils) GoogleTranslateToCN

func (g *GoogleTranslationUtils) GoogleTranslateToCN(text string, source string) (string, error)

func (*GoogleTranslationUtils) GoogleTranslateToEn

func (g *GoogleTranslationUtils) GoogleTranslateToEn(text string, source string) (string, error)

type HttpUtils

type HttpUtils struct{}

func NewHttpUtils

func NewHttpUtils() *HttpUtils

type LangTranslatorUtils

type LangTranslatorUtils struct {
	T2s *opencc.OpenCC
	S2t *opencc.OpenCC
	// contains filtered or unexported fields
}

func NewLangTranslatorUtils

func NewLangTranslatorUtils() *LangTranslatorUtils

func (*LangTranslatorUtils) Init

func (t *LangTranslatorUtils) Init()

type NumUtils

type NumUtils struct {
}

func NewNumUtils

func NewNumUtils() *NumUtils

func (*NumUtils) CheckNumStrInRange

func (n *NumUtils) CheckNumStrInRange(s string, min float64, max float64) (bool, error)

CheckNumStrInRange 检查一个字符串数字,大小是否在指定的范围内

func (*NumUtils) DecimalFormatBanker

func (n *NumUtils) DecimalFormatBanker(value decimal.Decimal) string

DecimalFormatBanker 使用银行家舍入法格式化decimal类型值为两位小数

func (*NumUtils) FormatNumStrToDecimalAndShift

func (n *NumUtils) FormatNumStrToDecimalAndShift(number string, decimals uint) decimal.Decimal

FormatNumStrToDecimalAndShift 输入1000,4 ,那么会输出 0.1

func (*NumUtils) GetMaxNum

func (n *NumUtils) GetMaxNum(vals ...int) int

func (*NumUtils) HashIdToInt64

func (n *NumUtils) HashIdToInt64(id string, minLen uint8) (int64, error)

func (*NumUtils) Int64ToHashId

func (n *NumUtils) Int64ToHashId(number int64, minLen uint8) string

func (*NumUtils) MergeToDecimal

func (n *NumUtils) MergeToDecimal(number *big.Int, dec int) decimal.Decimal

MergeToDecimal 如果输入的number是100000,dec是10,那么:将100000除以10000000000 (即10的10次方) 得到的结果是0.00001

func (*NumUtils) RandomInt

func (n *NumUtils) RandomInt(min, max int) int

func (*NumUtils) StrToDecimalTruncate

func (n *NumUtils) StrToDecimalTruncate(s string, precision int32) decimal.Decimal

StrToDecimalTruncate 将字符串数字变成decimal类型,保留指定小数位数,多余的全部放弃,不做四舍五入

type PwdUtils

type PwdUtils struct{}

func (*PwdUtils) Decrypt

func (p *PwdUtils) Decrypt(ciphertext, key string) (string, error)

Decrypt 使用 AES 解密数据

func (*PwdUtils) Encrypt

func (p *PwdUtils) Encrypt(plaintext, key string) (string, error)

Encrypt 使用 AES 加密数据

func (*PwdUtils) GenerateSalt

func (p *PwdUtils) GenerateSalt() (string, error)

GenerateSalt 生成一个随机盐值

func (*PwdUtils) HashPassword

func (p *PwdUtils) HashPassword(password, salt string) (string, error)

HashPassword 使用 Argon2id 对密码进行加盐哈希

func (*PwdUtils) VerifyPassword

func (p *PwdUtils) VerifyPassword(password, salt, hash string) (bool, error)

VerifyPassword 验证密码

type ResultData

type ResultData struct {
	Data struct {
		Translations []struct {
			TranslatedText string `json:"translatedText"`
		} `json:"translations"`
	} `json:"data"`
}

type StrUtils

type StrUtils struct{}

func NewStrUtils

func NewStrUtils() *StrUtils

func (*StrUtils) FilterEmptyChar

func (s *StrUtils) FilterEmptyChar(str string) string

func (*StrUtils) GenStrBySeed

func (s *StrUtils) GenStrBySeed(input, seed string) string

GenStrBySeed 根据给定的字符串和种子生成一个可重现的新字符串(不建议用到密码)

func (*StrUtils) GetDirNameFromSnowflakeID

func (s *StrUtils) GetDirNameFromSnowflakeID(snowflakeID int64) string

func (*StrUtils) IsAlphaNum

func (s *StrUtils) IsAlphaNum(str string) bool

func (*StrUtils) Length

func (s *StrUtils) Length(str string) int

func (*StrUtils) Md5

func (s *StrUtils) Md5(str string) string

func (*StrUtils) NanoTimestampStr

func (s *StrUtils) NanoTimestampStr() string

func (*StrUtils) PadCnSpaceChar

func (s *StrUtils) PadCnSpaceChar(label string, spaces int) string

PadCnSpaceChar 使用中文空格为字符串填充

func (*StrUtils) ProtoMessageToJson

func (s *StrUtils) ProtoMessageToJson(msg proto.Message) (string, error)

func (*StrUtils) RandomId

func (s *StrUtils) RandomId() string

func (*StrUtils) RegexpMatch

func (s *StrUtils) RegexpMatch(text string, pattern string) bool

func (*StrUtils) StrToInt64

func (s *StrUtils) StrToInt64(intStr string) (int64, error)

func (*StrUtils) UUIDNoDash

func (s *StrUtils) UUIDNoDash() string

func (*StrUtils) UniqueStrings

func (s *StrUtils) UniqueStrings(input []string) []string

UniqueStrings 返回一个新的切片,其中包含原切片中的唯一字符串

type StructUtils

type StructUtils struct{}

func NewStructUtils

func NewStructUtils() *StructUtils

type TimeUtils

type TimeUtils struct{}

func NewTimeUtils

func NewTimeUtils() *TimeUtils

func (*TimeUtils) SetTimezone

func (t *TimeUtils) SetTimezone(tz ...string)

type Translator

type Translator struct {
	T2s *opencc.OpenCC
	S2t *opencc.OpenCC
	// contains filtered or unexported fields
}

Directories

Path Synopsis
cloudserver
hwc
db
exchange
okx
Package snowflake provides a very simple Twitter snowflake generator and parser.
Package snowflake provides a very simple Twitter snowflake generator and parser.

Jump to

Keyboard shortcuts

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