goutils

package module
v1.8.62 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2024 License: LGPL-3.0 Imports: 44 Imported by: 0

README

go-utils

Warning : Not Finished


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)

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) Decrypt

func (u *CryptoUtils) Decrypt(cipherText string, pass string) (string, error)

func (*CryptoUtils) Encrypt

func (u *CryptoUtils) Encrypt(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 JsonUtils

type JsonUtils struct{}

func NewJsonUtils

func NewJsonUtils() *JsonUtils

func (*JsonUtils) JSONPrettyFormat

func (ju *JsonUtils) JSONPrettyFormat(in string) string

func (*JsonUtils) ToJSONUnsafe

func (ju *JsonUtils) ToJSONUnsafe(payload interface{}, pretty bool) string

ToJSONUnsafe returns "{}" on failure case

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 NetUtils

type NetUtils struct{}

func NewNetUtils

func NewNetUtils() *NetUtils

func (*NetUtils) GetLocalIP

func (n *NetUtils) GetLocalIP() string

func (*NetUtils) IsPrivateIP

func (n *NetUtils) IsPrivateIP(ip net.IP) bool

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的小数点向左移动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) Calculator

func (s *StrUtils) Calculator(exp string) (string, error)

Calculator 输入字符串数学表达式,将计算出结果

func (*StrUtils) FilterEmptyChar

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

func (*StrUtils) GenSha1

func (s *StrUtils) GenSha1(input 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) RegexpMatch

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

func (*StrUtils) StrToInt64

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

func (*StrUtils) StringToNumber

func (s *StrUtils) StringToNumber(str string) uint32

func (*StrUtils) UniqueStrings

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

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

type StructUtils

type StructUtils struct{}

func NewStructUtils

func NewStructUtils() *StructUtils

func (*StructUtils) MergeStructData

func (s *StructUtils) MergeStructData(existing, newData interface{}) interface{}

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

func (*StructUtils) StructToMap

func (s *StructUtils) StructToMap(configStruct interface{}) (map[string]interface{}, error)

StructToMap 将结构体转换为 map

type TimeUtils

type TimeUtils struct{}

func NewTimeUtils

func NewTimeUtils() *TimeUtils

func (*TimeUtils) CompareTimeStrings

func (t *TimeUtils) CompareTimeStrings(t1, t2 string) (int, error)

CompareTimeStrings 比较两个时间字符串,返回 -1, 0, 1 分别表示第一个时间小于、等于、大于第二个时间

func (*TimeUtils) SetTimezone

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

func (*TimeUtils) TimeDifference

func (t *TimeUtils) TimeDifference(t1, t2 string) (time.Duration, error)

TimeDifference 计算两个时间字符串之间的时间间隔

type Translator

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

Directories

Path Synopsis
cache
cloudserver
hwc
constants
db
exchange
okx
v2
dt
fs
id
ip
num
pwd
rnd
str
ua

Jump to

Keyboard shortcuts

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