goutils

package module
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: May 23, 2024 License: LGPL-3.0 Imports: 42 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)

func MergeStructData

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

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

Types

type AesUtils added in v1.1.0

type AesUtils struct{}

func NewAesUtils added in v1.1.0

func NewAesUtils() *AesUtils

func (*AesUtils) EncryptAES added in v1.1.0

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

func (*AesUtils) PKCS7Padding added in v1.1.0

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

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

type ConsoleUtils added in v1.1.0

type ConsoleUtils struct{}

func NewConsoleUtils added in v1.1.0

func NewConsoleUtils() *ConsoleUtils

func (*ConsoleUtils) Black added in v1.1.0

func (c *ConsoleUtils) Black(txt string)

func (*ConsoleUtils) BlackBold added in v1.1.0

func (c *ConsoleUtils) BlackBold(txt string)

func (*ConsoleUtils) Green added in v1.1.0

func (c *ConsoleUtils) Green(txt string)

func (*ConsoleUtils) Red added in v1.1.0

func (c *ConsoleUtils) Red(txt string)

type CryptoUtils added in v1.1.0

type CryptoUtils struct{}

func NewCryptoUtils added in v1.1.0

func NewCryptoUtils() *CryptoUtils

func (*CryptoUtils) Decrypt added in v1.1.14

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

func (*CryptoUtils) Encrypt added in v1.1.14

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

type FFMpegUtils added in v1.1.0

type FFMpegUtils struct{}

func NewFFMpegUtils added in v1.1.0

func NewFFMpegUtils() *FFMpegUtils

func (*FFMpegUtils) H264ToHls added in v1.1.0

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

func (*FFMpegUtils) ToHlsNonH264 added in v1.1.0

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

type FFProbeUtils added in v1.1.0

type FFProbeUtils struct{}

func NewFFProbeUtils added in v1.1.0

func NewFFProbeUtils() *FFProbeUtils

func (*FFProbeUtils) GetBitRates added in v1.1.0

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

func (*FFProbeUtils) GetCodecNames added in v1.1.0

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

func (*FFProbeUtils) GetDuration added in v1.1.0

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

func (*FFProbeUtils) GetFormatName added in v1.1.0

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

func (*FFProbeUtils) GetResolution added in v1.1.0

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

func (*FFProbeUtils) GetVideoDetails added in v1.1.0

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

func (*FFProbeUtils) IsH264 added in v1.1.0

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

func (*FFProbeUtils) IsValidExt added in v1.1.0

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

type GoogleTranslationUtils added in v1.1.0

type GoogleTranslationUtils struct{}

func NewGoogleTranslationUtils added in v1.1.0

func NewGoogleTranslationUtils() *GoogleTranslationUtils

func (*GoogleTranslationUtils) GoogleDetectLang added in v1.1.0

func (g *GoogleTranslationUtils) GoogleDetectLang(text string)

func (*GoogleTranslationUtils) GoogleTranslateToCN added in v1.1.0

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

func (*GoogleTranslationUtils) GoogleTranslateToEn added in v1.1.0

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

type HttpUtils added in v1.1.0

type HttpUtils struct{}

func NewHttpUtils added in v1.1.0

func NewHttpUtils() *HttpUtils

type JsonUtils added in v1.1.22

type JsonUtils struct{}

func NewJsonUtils added in v1.1.22

func NewJsonUtils() *JsonUtils

func (*JsonUtils) JSONPrettyFormat added in v1.1.22

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

func (*JsonUtils) ToJSONUnsafe added in v1.1.22

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

ToJSONUnsafe returns "{}" on failure case

type LangTranslatorUtils added in v1.1.0

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

func NewLangTranslatorUtils added in v1.1.0

func NewLangTranslatorUtils() *LangTranslatorUtils

func (*LangTranslatorUtils) Init added in v1.1.0

func (t *LangTranslatorUtils) Init()

type NumUtils added in v1.1.0

type NumUtils struct {
}

func NewNumUtils added in v1.1.0

func NewNumUtils() *NumUtils

func (*NumUtils) CheckNumStrInRange added in v1.1.0

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

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

func (*NumUtils) DecimalFormatBanker added in v1.1.0

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

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

func (*NumUtils) FormatNumStrToDecimalAndShift added in v1.1.0

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

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

func (*NumUtils) GetMaxNum added in v1.1.0

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

func (*NumUtils) HashIdToInt64 added in v1.1.0

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

func (*NumUtils) Int64ToHashId added in v1.1.0

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

func (*NumUtils) MergeToDecimal added in v1.1.0

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

MergeToDecimal 如果输入的number是100000,dec是10,那么:将100000的小数点向左移动10位,得到的结果是0.00001

func (*NumUtils) RandomInt added in v1.1.0

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

func (*NumUtils) StrToDecimalTruncate added in v1.1.0

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

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

type PwdUtils added in v1.1.11

type PwdUtils struct{}

func (*PwdUtils) Decrypt added in v1.1.11

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

Decrypt 使用 AES 解密数据

func (*PwdUtils) Encrypt added in v1.1.11

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

Encrypt 使用 AES 加密数据

func (*PwdUtils) GenerateSalt added in v1.1.11

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

GenerateSalt 生成一个随机盐值

func (*PwdUtils) HashPassword added in v1.1.11

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

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

func (*PwdUtils) VerifyPassword added in v1.1.11

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 added in v1.1.0

type StrUtils struct{}

func NewStrUtils added in v1.1.0

func NewStrUtils() *StrUtils

func (*StrUtils) FilterEmptyChar added in v1.1.0

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

func (*StrUtils) GenSha1 added in v1.1.12

func (s *StrUtils) GenSha1(input string) string

func (*StrUtils) GenStrBySeed added in v1.1.11

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

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

func (*StrUtils) GetDirNameFromSnowflakeID added in v1.1.0

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

func (*StrUtils) IsAlphaNum added in v1.1.0

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

func (*StrUtils) Length added in v1.1.0

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

func (*StrUtils) Md5 added in v1.1.0

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

func (*StrUtils) NanoTimestampStr added in v1.1.0

func (s *StrUtils) NanoTimestampStr() string

func (*StrUtils) PadCnSpaceChar added in v1.1.0

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

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

func (*StrUtils) ProtoMessageToJson added in v1.1.0

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

func (*StrUtils) RandomId added in v1.1.0

func (s *StrUtils) RandomId() string

func (*StrUtils) RegexpMatch added in v1.1.0

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

func (*StrUtils) StrToInt64 added in v1.1.0

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

func (*StrUtils) UUIDNoDash added in v1.1.0

func (s *StrUtils) UUIDNoDash() string

func (*StrUtils) UniqueStrings added in v1.1.0

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

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

type StructUtils added in v1.1.0

type StructUtils struct{}

func NewStructUtils added in v1.1.0

func NewStructUtils() *StructUtils

type TimeUtils added in v1.1.0

type TimeUtils struct{}

func NewTimeUtils added in v1.1.0

func NewTimeUtils() *TimeUtils

func (*TimeUtils) CompareTimeStrings added in v1.2.5

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

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

func (*TimeUtils) SetTimezone added in v1.1.0

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

func (*TimeUtils) TimeDifference added in v1.2.5

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