utils

package
v3.0.5 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2025 License: MIT Imports: 48 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MM_DD                   = "MM-dd"
	YYYYMM                  = "yyyyMM"
	YYYY_MM                 = "yyyy-MM"
	YYYY_MM_DD              = "yyyy-MM-dd"
	YYYYMMDD                = "yyyyMMdd"
	YYYYMMDDHHMMSS          = "yyyyMMddHHmmss"
	YYYYMMDDHHMM            = "yyyyMMddHHmm"
	YYYYMMDDHH              = "yyyyMMddHH"
	YYMMDDHHMM              = "yyMMddHHmm"
	MM_DD_HH_MM             = "MM-dd HH:mm"
	MM_DD_HH_MM_SS          = "MM-dd HH:mm:ss"
	YYYY_MM_DD_HH_MM        = "yyyy-MM-dd HH:mm"
	YYYY_MM_DD_HH_MM_SS     = "yyyy-MM-dd HH:mm:ss"
	YYYY_MM_DD_HH_MM_SS_SSS = "yyyy-MM-dd HH:mm:ss.SSS"

	MM_DD_EN                   = "MM/dd"
	YYYY_MM_EN                 = "yyyy/MM"
	YYYY_MM_DD_EN              = "yyyy/MM/dd"
	MM_DD_HH_MM_EN             = "MM/dd HH:mm"
	MM_DD_HH_MM_SS_EN          = "MM/dd HH:mm:ss"
	YYYY_MM_DD_HH_MM_EN        = "yyyy/MM/dd HH:mm"
	YYYY_MM_DD_HH_MM_SS_EN     = "yyyy/MM/dd HH:mm:ss"
	YYYY_MM_DD_HH_MM_SS_SSS_EN = "yyyy/MM/dd HH:mm:ss.SSS"

	MM_DD_CN               = "MM月dd日"
	YYYY_MM_CN             = "yyyy年MM月"
	YYYY_MM_DD_CN          = "yyyy年MM月dd日"
	MM_DD_HH_MM_CN         = "MM月dd日 HH:mm"
	MM_DD_HH_MM_SS_CN      = "MM月dd日 HH:mm:ss"
	YYYY_MM_DD_HH_MM_CN    = "yyyy年MM月dd日 HH:mm"
	YYYY_MM_DD_HH_MM_SS_CN = "yyyy年MM月dd日 HH:mm:ss"

	HH_MM       = "HH:mm"
	HH_MM_SS    = "HH:mm:ss"
	HH_MM_SS_MS = "HH:mm:ss.SSS"
)

Variables

This section is empty.

Functions

func AesDecode deprecated

func AesDecode(encryptedString, key string) (string, error)

AesDecode aes解密

Deprecated: AesDecode is deprecated,it will be removed in the future.

Please use Aes().Decode() instead.

使用CFB

key应该是一个16或24或32位长度的字符

func AesEncode deprecated

func AesEncode(rawString, key string) (string, error)

AesEncode aes加密

Deprecated: AesEncode is deprecated,it will be removed in the future.

Please use Aes().Encode() instead.

使用CFB

key应该是一个16或24或32位长度的字符

func Base64Decode deprecated

func Base64Decode(encodedString string) ([]byte, error)

Base64Decode base64解码

Deprecated: Base64Decode is deprecated,it will be removed in the future.

Please use Base64().Decode() instead.

func Base64Encode deprecated

func Base64Encode(rawBytes []byte) string

Base64Encode base64编码

Deprecated: Base64Encode is deprecated,it will be removed in the future.

Please use Base64().Encode() instead.

func BytesToStr added in v3.0.5

func BytesToStr(b []byte) string

BytesToStr 字节数组转换为字符串

func CharCodeAt deprecated added in v3.0.4

func CharCodeAt(character string) rune

CharCodeAt 返回字符对应的ASCII码

Deprecated: CharCodeAt is deprecated,it will be removed in the future.

Please use String().CharCodeAt() instead.

func Crc32Checksum deprecated added in v3.0.2

func Crc32Checksum(data []byte, table *crc32.Table) uint32

Crc32Checksum 求crc32校验码

Deprecated: Crc32Checksum is deprecated,it will be removed in the future.

Please use Crc32().Checksum() instead.

func Crc32ChecksumIEEE deprecated added in v3.0.2

func Crc32ChecksumIEEE(data []byte) uint32

Crc32ChecksumIEEE 求crc32校验码

Deprecated: Crc32ChecksumIEEE is deprecated,it will be removed in the future.

Please use Crc32().ChecksumIEEE() instead.

使用IEEE多项式

func Crc64Checksum deprecated added in v3.0.2

func Crc64Checksum(data []byte, table *crc64.Table) uint64

Crc64Checksum 求crc64校验码

Deprecated: Crc64Checksum is deprecated,it will be removed in the future.

Please use Crc64().Checksum() instead.

func Crc64ChecksumECMA deprecated added in v3.0.2

func Crc64ChecksumECMA(data []byte) uint64

Crc64ChecksumECMA 求crc64校验码

Deprecated: Crc64ChecksumECMA is deprecated,it will be removed in the future.

Please use Crc64().ChecksumECMA() instead.

使用ECMA多项式

func FileAppendContents deprecated

func FileAppendContents(content []byte, dst string) error

FileAppendContents 将内容写入文件(追加写)

Deprecated: FileAppendContents is deprecated,it will be removed in the future.

Please use File().AppendContents() instead.

content []byte 写入的内容

dst string 写入的目标地址

func FileExists deprecated

func FileExists(dst string) bool

FileExists 检查文件上是否存在

Deprecated: FileExists is deprecated,it will be removed in the future.

Please use File().Exists() instead.

dst string 目标地址

func FileExistsWithError deprecated

func FileExistsWithError(dst string) (bool, error)

FileExistsWithError 检查文件上是否存在(会返回错误信息)

Deprecated: FileExistsWithError is deprecated,it will be removed in the future.

Please use File().ExistsWithError() instead.

dst string 目标地址

func FileExt deprecated

func FileExt(filename string) string

FileExt 获取文件扩展名

Deprecated: FileExt is deprecated,it will be removed in the future.

Please use File().Ext() instead.

根据文件名最后一个.分隔来切分获取

func FileGetContents deprecated

func FileGetContents(filename string) ([]byte, error)

FileGetContents 获取文件内容

Deprecated: FileGetContents is deprecated,it will be removed in the future.

Please use File().GetContents() instead.

filename string 文件地址

func FileGetContentsReadLine deprecated

func FileGetContentsReadLine(dst string) (<-chan string, error)

FileGetContentsReadLine 逐行读取文件内容

Deprecated: FileGetContentsReadLine is deprecated,it will be removed in the future.

Please use File().GetContentsReadLine() instead.

func FilePutContents deprecated

func FilePutContents(content []byte, dst string) error

FilePutContents 将内容写入文件(覆盖写)

Deprecated: FilePutContents is deprecated,it will be removed in the future.

Please use File().PutContents() instead.

content []byte 写入的内容

dst string 写入的目标地址

func FormatDate deprecated added in v3.0.1

func FormatDate(date time.Time, dateStyle DateStyle) string

FormatDate 时间对象转字符串

Deprecated: FormatDate is deprecated,it will be removed in the future.

Please use Datetime().FormatDate() instead.

func FromCharCode deprecated added in v3.0.4

func FromCharCode(code int32) string

FromCharCode 返回ASCII码对应的字符

Deprecated: FromCharCode is deprecated,it will be removed in the future.

Please use String().FromCharCode() instead.

Note

常规ASCII码表范围为0~127

扩展ASCII码表范围为128~255

more: https://www.rfc-editor.org/rfc/rfc698.txt

func GenerateVAPIDKeys deprecated

func GenerateVAPIDKeys() (privateKey string, publicKey string, err error)

GenerateVAPIDKeys 生成web push的公私钥

Deprecated: GenerateVAPIDKeys is deprecated,it will be removed in the future.

Please use WebPush().GenerateVAPIDKeys() instead.

func GetLocalIP deprecated

func GetLocalIP() (string, error)

GetLocalIP 获取本地ip地址(单播地址)

Deprecated: GetLocalIP is deprecated,it will be removed in the future.

Please use IP().GetLocal() instead.

func GzipCompress deprecated added in v3.0.5

func GzipCompress(content []byte) []byte

GzipCompress gzip压缩

Deprecated: GzipCompress is deprecated,it will be removed in the future.

Please use Gzip().Compress() instead.

使用 gzip.DefaultCompression 压缩等级

func GzipDecompress deprecated added in v3.0.5

func GzipDecompress(content []byte) []byte

GzipDecompress gzip解压

Deprecated: GzipDecompress is deprecated,it will be removed in the future.

Please use Gzip().Decompress() instead.

func ListeningExitSignal deprecated

func ListeningExitSignal(wg *sync.WaitGroup)

ListeningExitSignal 监听系统退出信号

Deprecated: ListeningExitSignal is deprecated,it will be removed in the future.

Please use Signal().ListeningExit() instead.

func LookupCNAME deprecated added in v3.0.5

func LookupCNAME(domain, cnameTarget string) bool

LookupCNAME 查询域名cname记录

Deprecated: LookupCNAME is deprecated,it will be removed in the future.

Please use Domain().LookupCNAME() instead.

注意

nslookup的结果会在域名后增加一个「.」, 因此此函数在对比前会检测cnameTarget参数是否以「.」 结尾,如果不是,则会在结尾加上「.」,然后再进行对比。

func MD5Encode deprecated added in v3.0.4

func MD5Encode(rawString string) string

MD5Encode md5编码

Deprecated: MD5Encode is deprecated,it will be removed in the future.

Please use MD5().Encode() instead.

func ParseDate deprecated added in v3.0.1

func ParseDate(date, layout string, loc *time.Location) (time.Time, error)

ParseDate 解析时间

Deprecated: FormatDate is deprecated,it will be removed in the future.

Please use Datetime().ParseDate() instead.

string解析到time对象

func Pow deprecated added in v3.0.5

func Pow(x, y int64) int64

Pow 计算x的y次幂

Deprecated: Pow is deprecated,it will be removed in the future.

Please use Number().Pow() instead.

Note

若y小于0,将panic

func PrintSwaggerControllerInfo deprecated

func PrintSwaggerControllerInfo(param SwaggerControllerInfoParamDeprecated) string

PrintSwaggerControllerInfo 打印swagger控制器信息

Deprecated: PrintSwaggerControllerInfo is deprecated,it will be removed in the future.

Please use Swagger().PrintControllerInfo() instead.

用于生成swagger注释

func PrintSwaggerSummaryInfo deprecated

func PrintSwaggerSummaryInfo(param SwaggerSummaryInfoParamDeprecated) string

PrintSwaggerSummaryInfo 打印swagger概览信息参数

Deprecated: PrintSwaggerSummaryInfo is deprecated,it will be removed in the future.

Please use Swagger().PrintSummaryInfo() instead.

用于生成swagger注释

func PrintVersion deprecated added in v3.0.1

func PrintVersion(fields VersionInfoFieldsDeprecated)

PrintVersion 打印版本信息

Deprecated: PrintVersion is deprecated,it will be removed in the future.

Please use Version().Print() instead.

func RSADecrypt deprecated

func RSADecrypt(encodedString string, privateKey []byte) (string, error)

RSADecrypt rsa解密

Deprecated: RSADecrypt is deprecated,it will be removed in the future.

Please use RSA().Decrypt() instead.

func RSAEncrypt deprecated

func RSAEncrypt(rawString string, publicKey []byte) (string, error)

RSAEncrypt rsa加密

Deprecated: RSAEncrypt is deprecated,it will be removed in the future.

Please use RSA().Encrypt() instead.

func RSASign deprecated

func RSASign(rawStringBytes, privateKey []byte) (string, error)

RSASign rsa加签

Deprecated: RSASign is deprecated,it will be removed in the future.

Please use RSA().Sign() instead.

func RSAVerifySign deprecated

func RSAVerifySign(rawStringBytes, sign, publicKey []byte) (bool, error)

RSAVerifySign rsa验签

Deprecated: RSAVerifySign is deprecated,it will be removed in the future.

Please use RSA().VerifySign() instead.

func RandomComplexString deprecated added in v3.0.2

func RandomComplexString(length int) string

RandomComplexString 随机字符串(可带特殊符号)

Deprecated: RandomComplexString is deprecated,it will be removed in the future.

Please use String().RandomComplexString() instead.

func RandomDigitalChars deprecated

func RandomDigitalChars(length int) string

RandomDigitalChars 随机字符串(数字)

Deprecated: RandomDigitalChars is deprecated,it will be removed in the future.

Please use String().RandomDigitalChars() instead.

func RandomFloat64 deprecated added in v3.0.5

func RandomFloat64(start, end float64, precision int) float64

RandomFloat64 在指定范围内取随机浮点数

Deprecated: RandomFloat64 is deprecated,it will be removed in the future.

Please use Number().RandomFloat64() instead.

start和end同时支持正负数

precision为精度,此参数将限定返回值的最大小数位数

结果值区间 ∈ [start, end)

Note

若start大于end将panic

Example:

result := RandomFloat64(10.10, 20.20, 2) //-> 16.22

result := RandomFloat64(-10.10, 20.20, 3) //-> -7.222

result := RandomFloat64(-20.20, -10.10101010101, 4) //-> -8.1234

func RandomInt64 deprecated added in v3.0.5

func RandomInt64(start, end int64) int64

RandomInt64 在指定范围内取随机整数

Deprecated: RandomInt64 is deprecated,it will be removed in the future.

Please use Number().RandomInt64() instead.

start和end同时支持正负数

结果值区间 ∈ [start, end)

Note

若start大于end将panic

Example:

result := RandomInt64(10, 20) //-> 13

result := RandomInt64(-10, 20) //-> 3

result := RandomInt64(-20, -10) //-> -7

func RandomLetters deprecated

func RandomLetters(length int) string

RandomLetters 随机字符串(字母)

Deprecated: RandomLetters is deprecated,it will be removed in the future.

Please use String().RandomLetters() instead.

func RandomString added in v3.0.4

func RandomString(length int) string

RandomString 随机字符串(字母+数字)

func RedisClusterLock

func RedisClusterLock(key string) bool

RedisClusterLock redis锁-上锁(使用cluster)

using SetNX

func RedisClusterLockWithContext added in v3.0.4

func RedisClusterLockWithContext(ctx context.Context, key string) bool

RedisClusterLockWithContext redis锁-上锁(使用cluster)

using SetNX

func RedisClusterUnlock

func RedisClusterUnlock(key string)

RedisClusterUnlock redis锁-解锁(使用cluster)

using SetNX

func RedisClusterUnlockWithContext added in v3.0.4

func RedisClusterUnlockWithContext(ctx context.Context, key string)

RedisClusterUnlockWithContext redis锁-解锁(使用cluster)

using SetNX

func RedisLock deprecated

func RedisLock(ctx context.Context, key string)

RedisLock redis锁-上锁(自动推测连接类型)

Deprecated: RedisLock is deprecated,it will be removed in the future.

Please use RedisLocker().Lock() instead.

using SetNX

与之对应的是使用 RedisUnlock 解锁

Note

该方法会阻塞住线程直到上锁成功 或者 触发ctx.Done()

func RedisStandaloneLock added in v3.0.1

func RedisStandaloneLock(key string) bool

RedisStandaloneLock redis锁-上锁(使用standalone)

using SetNX

func RedisStandaloneLockWithContext added in v3.0.4

func RedisStandaloneLockWithContext(ctx context.Context, key string) bool

RedisStandaloneLockWithContext redis锁-上锁(使用standalone)

using SetNX

func RedisStandaloneUnlock added in v3.0.1

func RedisStandaloneUnlock(key string)

RedisStandaloneUnlock redis锁-解锁(使用standalone)

using SetNX

func RedisStandaloneUnlockWithContext added in v3.0.4

func RedisStandaloneUnlockWithContext(ctx context.Context, key string)

RedisStandaloneUnlockWithContext redis锁-解锁(使用standalone)

using SetNX

func RedisTryLock deprecated added in v3.0.2

func RedisTryLock(key string) bool

RedisTryLock redis锁-尝试上锁(自动推测连接类型)

Deprecated: RedisTryLock is deprecated,it will be removed in the future.

Please use RedisLocker().TryLock() instead.

using SetNX

与之对应的是使用 RedisUnlock 解锁

Note

该方法会立即返回锁定成功与否的结果

func RedisTryLockWithContext deprecated added in v3.0.4

func RedisTryLockWithContext(ctx context.Context, key string) bool

RedisTryLockWithContext redis锁-尝试上锁(自动推测连接类型)

Deprecated: RedisTryLockWithContext is deprecated,it will be removed in the future.

Please use RedisLocker().TryLockWithContext() instead.

using SetNX

与之对应的是使用 RedisUnlock 解锁

Note

该方法会立即返回锁定成功与否的结果

func RedisUnlock deprecated

func RedisUnlock(key string)

RedisUnlock redis锁-解锁(自动推测连接类型)

Deprecated: RedisUnlock is deprecated,it will be removed in the future.

Please use RedisLocker().Unlock() instead.

using SetNX

func RedisUnlockWithContext deprecated added in v3.0.4

func RedisUnlockWithContext(ctx context.Context, key string)

RedisUnlockWithContext redis锁-解锁(自动推测连接类型)

Deprecated: RedisUnlockWithContext is deprecated,it will be removed in the future.

Please use RedisLocker().UnlockWithContext() instead.

using SetNX

func RefererMatchDomain deprecated added in v3.0.5

func RefererMatchDomain(referer, domain string) bool

RefererMatchDomain refer是否匹配域名

Deprecated: RefererMatchDomain is deprecated,it will be removed in the future.

Please use Domain().RefererMatch() instead.

提示:

1.referer和域名大小写不敏感

2.此函数支持通配符域名检测

func ReportCertAndKeyWhetherMatch deprecated added in v3.0.5

func ReportCertAndKeyWhetherMatch(certData, keyData []byte) (bool, error)

ReportCertAndKeyWhetherMatch 报告证书和私钥是否匹配

Deprecated: ReportCertAndKeyWhetherMatch is deprecated,it will be removed in the future.

Please use Cert().ReportKeyWhetherMatch() instead.

func ReportCertValidity deprecated added in v3.0.5

func ReportCertValidity(domain string, pemData []byte) (bool, time.Time, time.Time, error)

ReportCertValidity 报告证书有效性

Deprecated: ReportCertValidity is deprecated,it will be removed in the future.

Please use Cert().ReportValidity() instead.

参数:

- domain: 域名

- pemData: 包含 -----BEGIN CERTIFICATE----- xx -----END CERTIFICATE----- 的证书链,格式为pem或crt

返回值:

- 是否有效

- 证书有效期开始时间

- 证书有效期结束时间

- 错误

func SM4ECBDecrypt deprecated added in v3.0.1

func SM4ECBDecrypt(hexKey, base64Raw string) (string, error)

SM4ECBDecrypt ECB解密

Deprecated: SM4ECBDecrypt is deprecated,it will be removed in the future.

Please use SM4().ECBDecrypt() instead.

hexKey 16进制key 长度32位

base64Raw 加密内容 base64格式

func SM4ECBEncrypt deprecated added in v3.0.1

func SM4ECBEncrypt(hexKey, raw string) (string, error)

SM4ECBEncrypt ECB加密

Deprecated: SM4ECBEncrypt is deprecated,it will be removed in the future.

Please use SM4().ECBEncrypt() instead.

hexKey 16进制key 长度32位

raw 待加密内容

func SaveFile2Dst deprecated

func SaveFile2Dst(file *multipart.FileHeader, dst string) error

SaveFile2Dst 将文件保存到目标地址(拷贝文件)

Deprecated: SaveFile2Dst is deprecated,it will be removed in the future.

Please use File().Save2Dst() instead.

file *multipart.FileHeader 文件

dst string 拷贝到的目标地址

func SendNotification deprecated

func SendNotification(privateKey, publicKey string, sub webpush.Subscription, subscriberEmail string, body PayloadDeprecated) error

SendNotification 发送通知

Deprecated: SendNotification is deprecated,it will be removed in the future.

Please use WebPush().SendNotification() instead.

func SendRequest deprecated added in v3.0.5

func SendRequest(method, url string, jsonPayload []byte, headers map[string]string, timeout ...time.Duration) (response []byte, statusCode int, err error)

SendRequest 发送请求

Deprecated: SendRequest is deprecated,it will be removed in the future.

Please use HttpClient().SendRequest() instead.

默认Content-Type为application/json; charset=utf-8

func StrToBytes added in v3.0.5

func StrToBytes(s string) []byte

StrToBytes 字符串转换为字节数组

func StringPaddingBoth deprecated added in v3.0.2

func StringPaddingBoth(rawString, padChar string, length int) string

StringPaddingBoth 向两端填充字符串

Deprecated: StringPaddingBoth is deprecated,it will be removed in the future.

Please use String().PaddingBoth() instead.

rawString 原字符

padChar 填充字符

length 最终字符长度

Note

如果填充长度不能均分,那么右侧多填充一个字符,如:

rawString = "a",padChar = "#",length = 4

则:

result = "#a##"

func StringPaddingLeft deprecated added in v3.0.2

func StringPaddingLeft(rawString, padChar string, length int) string

StringPaddingLeft 向左填充字符串

Deprecated: StringPaddingLeft is deprecated,it will be removed in the future.

Please use String().PaddingLeft() instead.

rawString 原字符

padChar 填充字符

length 最终字符长度

func StringPaddingRight deprecated added in v3.0.2

func StringPaddingRight(rawString, padChar string, length int) string

StringPaddingRight 向右填充字符串

Deprecated: StringPaddingRight is deprecated,it will be removed in the future.

Please use String().PaddingRight() instead.

rawString 原字符

padChar 填充字符

length 最终字符长度

func StringReverse deprecated added in v3.0.2

func StringReverse(s string) string

StringReverse 翻转字符串

Deprecated: StringReverse is deprecated,it will be removed in the future.

Please use String().Reverse() instead.

func StringShuffle deprecated added in v3.0.2

func StringShuffle(s string) string

StringShuffle 打乱字符串

Deprecated: StringShuffle is deprecated,it will be removed in the future.

Please use String().Shuffle() instead.

func ValidateDomain deprecated added in v3.0.5

func ValidateDomain(domain string) bool

ValidateDomain 验证域名是否合法

Deprecated: ValidateDomain is deprecated,it will be removed in the future.

Please use Domain().Validate() instead.

不支持通配符

func ValidateDomainWithWildcard deprecated added in v3.0.5

func ValidateDomainWithWildcard(domain string) bool

ValidateDomainWithWildcard 验证域名是否合法

Deprecated: ValidateDomainWithWildcard is deprecated,it will be removed in the future.

Please use Domain().ValidateWithWildcard() instead.

包含通配符规则验证

eg.

example.com -> ✔

x.example.com -> ✔

*.example.com -> ✔

*example.com -> ✖

example*.com -> ✖

func ValidateEmail deprecated

func ValidateEmail(email string) bool

ValidateEmail 验证邮箱格式

Deprecated: ValidateEmail is deprecated,it will be removed in the future.

Please use Validator().Email() instead.

func ValidateIdentityCard deprecated added in v3.0.1

func ValidateIdentityCard(idCard string) bool

ValidateIdentityCard (中国大陆)身份证格式校验

Deprecated: ValidateIdentityCard is deprecated,it will be removed in the future.

Please use Validator().IdentityCard() instead.

计算规则参考“中国国家标准化管理委员会”

官方文档@see http://www.gb688.cn/bzgk/gb/newGbInfo?hcno=080D6FBF2BB468F9007657F26D60013E

func Wordwrap deprecated

func Wordwrap(rawStr string, length int, split string) string

Wordwrap 以给定的字符和长度来打断字符串

Deprecated: Wordwrap is deprecated,it will be removed in the future.

Please use String().Wordwrap() instead.

func WrapRedisKey deprecated

func WrapRedisKey(appName, key string) string

WrapRedisKey 包装redis键名

Deprecated: WrapRedisKey is deprecated,it will be removed in the future.

Please use String().WrapRedisKey() instead.

给redis的键加入应用名前缀,如:

appName=game key=user

最终的redis键名为:game:user

此方法的主要作用是按应用来划分redis键名

Types

type CancelFunc added in v3.0.2

type CancelFunc func()

type DateStyle added in v3.0.1

type DateStyle string

DateStyle 日期格式

type HeapHelper added in v3.0.4

type HeapHelper interface {
	// Push 将数据添加到堆中
	Push(value IAnyValue)
	// Pop 将数据从堆中取出
	Pop() IAnyValue
}

func NewHeap added in v3.0.4

func NewHeap() HeapHelper

NewHeap 初始化一个全新的堆

它的作用是可以对任意数据类型的切片进行排序

实现 IAnyValue.SortByAsc 方法可以指定排序规则(升序、降序)

IAnyValue.GetScore 方法是排序的数值依据

type HeapStd added in v3.0.4

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

func (*HeapStd) Pop added in v3.0.4

func (hs *HeapStd) Pop() IAnyValue

func (*HeapStd) Push added in v3.0.4

func (hs *HeapStd) Push(value IAnyValue)

type IAes added in v3.0.5

type IAes interface {
	// Encode aes加密
	//
	// 使用CFB
	//
	// key应该是一个16或24或32位长度的字符
	Encode(rawString, key string) (string, error)
	// Decode aes解密
	//
	// 使用CFB
	//
	// key应该是一个16或24或32位长度的字符
	Decode(encryptedString, key string) (string, error)
}

IAes aes接口

func Aes added in v3.0.5

func Aes() IAes

Aes 实例化aes工具类

type IAnyValue added in v3.0.4

type IAnyValue interface {
	// GetScore 获取对比分值
	GetScore() float64
	// SortByAsc 指定排序规则
	//
	// true 为升序(小顶堆)
	//
	// false 为降序(大顶堆)
	SortByAsc() bool
}

IAnyValue 任意值接口

type IBase64 added in v3.0.5

type IBase64 interface {
	// Encode base64编码
	Encode(rawBytes []byte) string
	// Decode base64解码
	Decode(encodedString string) ([]byte, error)
}

IBase64 base64接口

func Base64 added in v3.0.5

func Base64() IBase64

Base64 实例化base64工具类

type ICert added in v3.0.5

type ICert interface {
	// ReportValidity 报告证书有效性
	//
	// 参数:
	//
	// - domain: 域名
	//
	// - pemData: 包含 -----BEGIN CERTIFICATE----- xx -----END CERTIFICATE----- 的证书链,格式为pem或crt
	//
	// 返回值:
	//
	// - 是否有效
	//
	// - 证书有效期开始时间
	//
	// - 证书有效期结束时间
	//
	// - 错误
	ReportValidity(domain string, pemData []byte) (bool, time.Time, time.Time, error)
	// ReportKeyWhetherMatch 报告证书和私钥是否匹配
	ReportKeyWhetherMatch(certData, keyData []byte) (bool, error)
}

func Cert added in v3.0.5

func Cert() ICert

Cert 实例化证书工具类

type ICrc32 added in v3.0.5

type ICrc32 interface {
	// Checksum 求crc32校验码
	Checksum(data []byte, table *crc32.Table) uint32
	// ChecksumIEEE 求crc32校验码
	//
	// 使用IEEE多项式
	ChecksumIEEE(data []byte) uint32
}

func Crc32 added in v3.0.5

func Crc32() ICrc32

Crc32 实例化crc32工具类

type ICrc64 added in v3.0.5

type ICrc64 interface {
	// Checksum 求crc64校验码
	Checksum(data []byte, table *crc64.Table) uint64
	// ChecksumECMA 求crc64校验码
	//
	// 使用ECMA多项式
	ChecksumECMA(data []byte) uint64
}

func Crc64 added in v3.0.5

func Crc64() ICrc64

Crc64 实例化crc64工具类

type IDatetime added in v3.0.5

type IDatetime interface {
	// FormatDate 时间对象转字符串
	FormatDate(date time.Time, dateStyle DateStyle) string
	// ParseDate 解析时间
	//
	// string解析到time对象
	ParseDate(date, layout string, loc *time.Location) (time.Time, error)
}

func Datetime added in v3.0.5

func Datetime() IDatetime

Datetime 实例化日期时间工具类

type IDomain added in v3.0.5

type IDomain interface {
	// Validate 验证域名是否合法
	//
	// 不支持通配符
	Validate(domain string) bool
	// ValidateWithWildcard 验证域名是否合法
	//
	// 包含通配符规则验证
	//
	// eg.
	//
	// example.com    -> ✔
	//
	// x.example.com  -> ✔
	//
	// *.example.com  -> ✔
	//
	// *example.com   -> ✖
	//
	// example*.com   -> ✖
	ValidateWithWildcard(domain string) bool
	// RefererMatch refer是否匹配域名
	//
	// 提示:
	//
	// 1.referer和域名大小写不敏感
	//
	// 2.此函数支持通配符域名检测
	RefererMatch(referer, domain string) bool
	// LookupCNAME 查询域名cname记录
	//
	// # 注意
	//
	// nslookup的结果会在域名后增加一个「.」,
	// 因此此函数在对比前会检测cnameTarget参数是否以「.」
	// 结尾,如果不是,则会在结尾加上「.」,然后再进行对比。
	LookupCNAME(domain, cnameTarget string) bool
}

func Domain added in v3.0.5

func Domain() IDomain

Domain 实例化domain工具类

type IFile added in v3.0.5

type IFile interface {
	// Save2Dst 将文件保存到目标地址(拷贝文件)
	//
	// file *multipart.FileHeader 文件
	//
	// dst string 拷贝到的目标地址
	Save2Dst(file *multipart.FileHeader, dst string) error
	// GetContents 获取文件内容
	//
	// filename string 文件地址
	GetContents(filename string) ([]byte, error)
	//PutContents 将内容写入文件(覆盖写)
	//
	// content []byte 写入的内容
	//
	// dst string 写入的目标地址
	PutContents(content []byte, dst string) error
	// AppendContents 将内容写入文件(追加写)
	//
	// content []byte 写入的内容
	//
	// dst string 写入的目标地址
	AppendContents(content []byte, dst string) error
	// Exists 检查文件上是否存在
	//
	// dst string 目标地址
	Exists(dst string) bool
	// ExistsWithError 检查文件上是否存在(会返回错误信息)
	//
	// dst string 目标地址
	ExistsWithError(dst string) (bool, error)
	// Ext 获取文件扩展名
	//
	// 根据文件名最后一个.分隔来切分获取
	Ext(filename string) string
	// GetContentsReadLine 逐行读取文件内容
	GetContentsReadLine(dst string) (<-chan string, error)
}

func File added in v3.0.5

func File() IFile

File 实例化file工具类

type IGzip added in v3.0.5

type IGzip interface {
	// Compress gzip压缩
	//
	// 使用 gzip.DefaultCompression 压缩等级
	Compress(content []byte) []byte
	// Decompress gzip解压
	Decompress(content []byte) []byte
}

func Gzip added in v3.0.5

func Gzip() IGzip

Gzip 实例化gzip工具类

type IHttpClient added in v3.0.5

type IHttpClient interface {
	// SendRequest 发送请求
	//
	// 默认Content-Type为application/json; charset=utf-8
	SendRequest(method, url string, jsonPayload []byte, headers map[string]string, timeout ...time.Duration) (response []byte, statusCode int, err error)
}

func HttpClient added in v3.0.5

func HttpClient() IHttpClient

HttpClient 实例化http client工具类

type IIP added in v3.0.5

type IIP interface {
	// GetLocal 获取本地ip地址(单播地址)
	GetLocal() (string, error)
}

func IP added in v3.0.5

func IP() IIP

IP 实例化ip工具类

type IMD5 added in v3.0.5

type IMD5 interface {
	// Encode md5编码
	Encode(rawString string) string
}

func MD5 added in v3.0.5

func MD5() IMD5

MD5 实例化md5工具类

type INumber added in v3.0.5

type INumber interface {
	// RandomInt64 在指定范围内取随机整数
	//
	// start和end同时支持正负数
	//
	// 结果值区间 ∈ [start, end)
	//
	// # Note
	//
	// 若start大于end将panic
	//
	// # Example:
	//
	// result := RandomInt64(10, 20)
	// //-> 13
	//
	// result := RandomInt64(-10, 20)
	// //-> 3
	//
	// result := RandomInt64(-20, -10)
	// //-> -7
	RandomInt64(start, end int64) int64
	// RandomFloat64 在指定范围内取随机浮点数
	//
	// start和end同时支持正负数
	//
	// precision为精度,此参数将限定返回值的最大小数位数
	//
	// 结果值区间 ∈ [start, end)
	//
	// # Note
	//
	// 若start大于end将panic
	//
	// # Example:
	//
	// result := RandomFloat64(10.10, 20.20, 2)
	// //-> 16.22
	//
	// result := RandomFloat64(-10.10, 20.20, 3)
	// //-> -7.222
	//
	// result := RandomFloat64(-20.20, -10.10101010101, 4)
	// //-> -8.1234
	RandomFloat64(start, end float64, precision int) float64
	// Pow 计算x的y次幂
	//
	// # Note
	//
	// 若y小于0,将panic
	Pow(x, y int64) int64
}

func Number added in v3.0.5

func Number() INumber

Number 实例化number工具类

type IRedisLocker added in v3.0.5

type IRedisLocker interface {
	// TryLock redis锁-尝试上锁(自动推测连接类型)
	//
	// using SetNX
	//
	// 与之对应的是使用 Unlock 解锁
	//
	// # Note
	//
	// 该方法会立即返回锁定成功与否的结果
	TryLock(key string) bool
	// TryLockWithContext redis锁-尝试上锁(自动推测连接类型)
	//
	// using SetNX
	//
	// 与之对应的是使用 Unlock 解锁
	//
	// # Note
	//
	// 该方法会立即返回锁定成功与否的结果
	TryLockWithContext(ctx context.Context, key string) bool
	// Lock redis锁-上锁(自动推测连接类型)
	//
	// using SetNX
	//
	// 与之对应的是使用 Unlock 解锁
	//
	// # Note
	//
	// 该方法会阻塞住线程直到上锁成功 或者 触发ctx.Done()
	Lock(ctx context.Context, key string)
	// Unlock redis锁-解锁(自动推测连接类型)
	//
	// using SetNX
	Unlock(key string)
	// UnlockWithContext redis锁-解锁(自动推测连接类型)
	//
	// using SetNX
	UnlockWithContext(ctx context.Context, key string)
}

func RedisLocker added in v3.0.5

func RedisLocker() IRedisLocker

RedisLocker 实例化redis锁工具类

type IRsa added in v3.0.5

type IRsa interface {
	// Encrypt rsa加密
	Encrypt(rawString string, publicKey []byte) (string, error)
	// Decrypt rsa解密
	Decrypt(encodedString string, privateKey []byte) (string, error)
	// Sign rsa加签
	Sign(rawStringBytes, privateKey []byte) (string, error)
	// VerifySign rsa验签
	VerifySign(rawStringBytes, sign, publicKey []byte) (bool, error)
}

func RSA added in v3.0.5

func RSA() IRsa

RSA 实例化rsa工具类

type ISM4 added in v3.0.5

type ISM4 interface {
	// ECBEncrypt ECB加密
	//
	// hexKey 16进制key 长度32位
	//
	// raw 待加密内容
	ECBEncrypt(hexKey, raw string) (string, error)
	// ECBDecrypt ECB解密
	//
	// hexKey 16进制key 长度32位
	//
	// base64Raw 加密内容 base64格式
	ECBDecrypt(hexKey, base64Raw string) (string, error)
}

func SM4 added in v3.0.5

func SM4() ISM4

SM4 实例化sm4工具类

type ISignal added in v3.0.5

type ISignal interface {
	// ListeningExit 监听系统退出信号
	ListeningExit(wg *sync.WaitGroup)
}

func Signal added in v3.0.5

func Signal() ISignal

Signal 实例化信号工具类

type IString added in v3.0.5

type IString interface {
	// Wordwrap 以给定的字符和长度来打断字符串
	Wordwrap(rawStr string, length int, split string) string
	// WrapRedisKey 包装redis键名
	//
	// 给redis的键加入应用名前缀,如:
	//
	// appName=game key=user
	//
	// 最终的redis键名为:game:user
	//
	// 此方法的主要作用是按应用来划分redis键名
	WrapRedisKey(appName, key string) string
	// RandomLetters 随机字符串(字母)
	RandomLetters(length int) string
	// RandomDigitalChars 随机字符串(数字)
	RandomDigitalChars(length int) string
	// RandomString 随机字符串(字母+数字)
	RandomString(length int) string
	// RandomComplexString 随机字符串(可带特殊符号)
	RandomComplexString(length int) string
	// Reverse 翻转字符串
	Reverse(s string) string
	// Shuffle 打乱字符串
	Shuffle(s string) string
	// PaddingLeft 向左填充字符串
	//
	// rawString 原字符
	//
	// padChar 填充字符
	//
	// length 最终字符长度
	PaddingLeft(rawString, padChar string, length int) string
	// PaddingRight 向右填充字符串
	//
	// rawString 原字符
	//
	// padChar 填充字符
	//
	// length 最终字符长度
	PaddingRight(rawString, padChar string, length int) string
	// PaddingBoth 向两端填充字符串
	//
	// rawString 原字符
	//
	// padChar 填充字符
	//
	// length 最终字符长度
	//
	// # Note
	//
	// 如果填充长度不能均分,那么右侧多填充一个字符,如:
	//
	// rawString = "a",padChar = "#",length = 4
	//
	// 则:
	//
	// result = "#a##"
	PaddingBoth(rawString, padChar string, length int) string
	// FromCharCode 返回ASCII码对应的字符
	//
	// # Note
	//
	// 常规ASCII码表范围为0~127
	//
	// 扩展ASCII码表范围为128~255
	//
	// more: https://www.rfc-editor.org/rfc/rfc698.txt
	FromCharCode(code int32) string
	// CharCodeAt 返回字符对应的ASCII码
	CharCodeAt(character string) rune
}

func String added in v3.0.5

func String() IString

String 实例化string工具类

type ISwagger added in v3.0.5

type ISwagger interface {
	// PrintSummaryInfo 打印swagger概览信息参数
	//
	// 用于生成swagger注释
	PrintSummaryInfo(param SwaggerSummaryInfoParam) string
	// PrintControllerInfo 打印swagger控制器信息
	//
	// 用于生成swagger注释
	PrintControllerInfo(param SwaggerControllerInfoParam) string
}

func Swagger added in v3.0.5

func Swagger() ISwagger

Swagger 实例化swagger工具类

type IValidator added in v3.0.5

type IValidator interface {
	// Email 验证邮箱格式
	Email(email string) bool
	// IdentityCard (中国大陆)身份证格式校验
	//
	// 计算规则参考“中国国家标准化管理委员会”
	//
	// 官方文档@see http://www.gb688.cn/bzgk/gb/newGbInfo?hcno=080D6FBF2BB468F9007657F26D60013E
	IdentityCard(idCard string) bool
}

func Validator added in v3.0.5

func Validator() IValidator

Validator 实例化validator工具类

type IVersion added in v3.0.5

type IVersion interface {
	// Print 打印版本信息
	Print(fields VersionInfoFields)
}

func Version added in v3.0.5

func Version() IVersion

Version 实例化version工具类

type IWebPush added in v3.0.5

type IWebPush interface {
	// GenerateVAPIDKeys 生成web push的公私钥
	GenerateVAPIDKeys() (privateKey string, publicKey string, err error)
	// SendNotification 发送通知
	SendNotification(privateKey, publicKey string, sub webpush.Subscription, subscriberEmail string, body Payload) error
}

func WebPush added in v3.0.5

func WebPush() IWebPush

WebPush 实例化web push工具类

type Payload

type Payload struct {
	Title string           `json:"title"`
	Body  string           `json:"body"`
	Icon  string           `json:"icon"`
	Data  PayloadDataField `json:"data"`
	Badge string           `json:"badge"`
}

Payload 消息推送载荷

type PayloadDataField

type PayloadDataField struct {
	URL string `json:"url"`
}

PayloadDataField 消息推送载荷-data字段

type PayloadDataFieldDeprecated added in v3.0.5

type PayloadDataFieldDeprecated struct {
	URL string `json:"url"`
}

PayloadDataFieldDeprecated 消息推送载荷-data字段

type PayloadDeprecated added in v3.0.5

type PayloadDeprecated struct {
	Title string                     `json:"title"`
	Body  string                     `json:"body"`
	Icon  string                     `json:"icon"`
	Data  PayloadDataFieldDeprecated `json:"data"`
	Badge string                     `json:"badge"`
}

PayloadDeprecated 消息推送载荷

type SwaggerControllerInfoParam

type SwaggerControllerInfoParam struct {
	FunctionName       string //方法名称
	FunctionDesc       string //方法描述
	Tag                string //分类标签
	Summary            string //简要标题
	Description        string //接口描述
	Method             string //请求方法
	RequestParamString string //请求参数字符
	ResponseBodyString string //返回体字符
	ApiPath            string //接口路径
	NeedAuthorize      bool   //是否需要授权
}

SwaggerControllerInfoParam 控制器信息参数

type SwaggerControllerInfoParamDeprecated added in v3.0.5

type SwaggerControllerInfoParamDeprecated struct {
	FunctionName       string //方法名称
	FunctionDesc       string //方法描述
	Tag                string //分类标签
	Summary            string //简要标题
	Description        string //接口描述
	Method             string //请求方法
	RequestParamString string //请求参数字符
	ResponseBodyString string //返回体字符
	ApiPath            string //接口路径
	NeedAuthorize      bool   //是否需要授权
}

SwaggerControllerInfoParamDeprecated 控制器信息参数

type SwaggerSummaryInfoParam

type SwaggerSummaryInfoParam struct {
	Title            string //标题
	Version          string //版本
	Description      string //描述
	TermOfServiceUrl string //服务条款地址
	ContactName      string //联系人
	ContactUrl       string //联系网址
	ContactEmail     string //联系邮箱
	LicenseUrl       string //证书网址
	Host             string //接口主机地址
	BasePath         string //接口公共前缀路径
	NeedAuthorize    bool   //是否需要token授权
}

SwaggerSummaryInfoParam 概览信息参数

type SwaggerSummaryInfoParamDeprecated added in v3.0.5

type SwaggerSummaryInfoParamDeprecated struct {
	Title            string //标题
	Version          string //版本
	Description      string //描述
	TermOfServiceUrl string //服务条款地址
	ContactName      string //联系人
	ContactUrl       string //联系网址
	ContactEmail     string //联系邮箱
	LicenseUrl       string //证书网址
	Host             string //接口主机地址
	BasePath         string //接口公共前缀路径
	NeedAuthorize    bool   //是否需要token授权
}

SwaggerSummaryInfoParamDeprecated 概览信息参数

type TIM

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

func NewTimeWithTimeZone

func NewTimeWithTimeZone(timeZone ...string) *TIM

NewTimeWithTimeZone 根据时区初始化时间

默认时区: Asia/Shanghai

func (*TIM) Date

func (t *TIM) Date() string

Date 获取格式化后的当前日期

func (*TIM) Datetime

func (t *TIM) Datetime() string

Datetime 获取格式化后的当前日期时间

func (*TIM) DatetimeTZ added in v3.0.4

func (t *TIM) DatetimeTZ() string

DatetimeTZ 获取格式化后的当前日期时间-tz

func (*TIM) Now

func (t *TIM) Now() time.Time

Now 获取当前时间对象(带时区)

func (*TIM) Time

func (t *TIM) Time() string

Time 获取格式化后的当前时间

type VersionInfoFields added in v3.0.1

type VersionInfoFields struct {
	AppName   string //应用名称
	Branch    string //版本分支
	Version   string //版本号
	Revision  string //commit id
	BuildDate string //编译时间
	GoVersion string //golang版本
}

VersionInfoFields 版本信息字段

type VersionInfoFieldsDeprecated added in v3.0.5

type VersionInfoFieldsDeprecated struct {
	AppName   string //应用名称
	Branch    string //版本分支
	Version   string //版本号
	Revision  string //commit id
	BuildDate string //编译时间
	GoVersion string //golang版本
}

VersionInfoFieldsDeprecated 版本信息字段

Jump to

Keyboard shortcuts

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