utils

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2025 License: LGPL-3.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalcDaysFromYearMonth

func CalcDaysFromYearMonth(year int, month int) int

CalcDaysFromYearMonth 返回给定年份和月份的天数

func CompareTime

func CompareTime(t1, t2 time.Time) bool

CompareTime 比较两个时间大小

func ConvertToStringSlice

func ConvertToStringSlice(data []interface{}) []string

func Decimal

func Decimal(value float64) float64

Decimal 保留两位小数

func Decrypt

func Decrypt(privateKeyFile, ciphertext string, types string) (plaintext string, err error)

Decrypt 使用私钥解密数据

func DecryptOAEP

func DecryptOAEP(privateKeyFile, ciphertext string) (plaintext string, err error)

DecryptOAEP 使用私钥解密数据

func DecryptPKCS1v15

func DecryptPKCS1v15(privateKeyFile, ciphertext string) (plaintext string, err error)

DecryptPKCS1v15 使用私钥解密数据

func DeleteFile

func DeleteFile(name string) error

删除文件

func DirSize

func DirSize(dirname string) string

DirSize 获取目录下所有文件大小

func Encrypt

func Encrypt(privateKeyFile, ciphertext string, types string) (plaintext string, err error)

Encrypt 使用公钥加密数据

func EncryptOAEP

func EncryptOAEP(publicKeyFile string, content string) (ciphertext string, err error)

EncryptOAEP 使用公钥加密数据

func EncryptPKCS1v15

func EncryptPKCS1v15(publicKeyFile string, content string) (ciphertext string, err error)

EncryptPKCS1v15 使用公钥加密数据

func EncryptPassword

func EncryptPassword(password, salt string) string

EncryptPassword 密码加密

func FileIsExisted

func FileIsExisted(filename string) bool

FileIsExisted 文件或文件夹是否存在

func FileSize

func FileSize(fileSize int64) string

FileSize 字节的单位转换 保留两位小数

func FormatSize

func FormatSize(size int64) string

FormatSize 格式化文件大小。

func GenerateKeyPair

func GenerateKeyPair(bits int, privateKeyFile string, publicKeyFile string) (err error)

GenerateKeyPair 生成RSA密钥对

func GetBetweenDates

func GetBetweenDates(sdate, edate string) []string

GetBetweenDates 根据开始日期和结束日期计算出时间段内所有日期 参数为日期格式,如:2020-01-01

func GetCityByIp

func GetCityByIp(ip string) string

GetCityByIp 获取ip所属城市

func GetClientIp

func GetClientIp(ctx context.Context) string

GetClientIp 获取客户端IP

func GetCurrentDateString

func GetCurrentDateString() string

GetCurrentDateString 获取当前日期字符串

func GetDomain

func GetDomain(ctx context.Context) string

GetDomain 获取当前请求接口域名

func GetHourBetweenDates

func GetHourBetweenDates(sdate, edate string) []string

func GetHourDiffer

func GetHourDiffer(startTime, endTime string) float64

GetHourDiffer 计算俩个时间差多少小时

func GetLocalIP

func GetLocalIP() (string, error)

GetLocalIP 获取服务器内网IP

func GetMin

func GetMin(a, b int64) int64

GetMin 返回两个整数中的较小值

func GetMinutesDiffer

func GetMinutesDiffer(startTime, endTime string) int

GetMinutesDiffer 计算俩个时间差多少分钟

func GetPublicIP

func GetPublicIP() (ip string, err error)

GetPublicIP 获取公网IP

func GetQuarterDay

func GetQuarterDay() (string, string)

GetQuarterDay 获得当前季度的初始和结束日期

func GetTime

func GetTime(i int, types int, begin string) (startTime string, endTime string, duration int, unit string)

GetTime 根据类型和开始时间获取时间段及长度

func GetTimeByInt

func GetTimeByInt(t1 int64) time.Time

GetTimeByInt 时间戳转时间

func GetTimeByType

func GetTimeByType(types int) (index int, begin string, end string)

GetTimeByType 根据类型获取开始时间、结束时间及差值 1 天 2 周 3 月 4 年

func GetTimeMills

func GetTimeMills(t time.Time) int64

GetTimeMills 转为时间戳->毫秒数

func GetTimeTagGroup

func GetTimeTagGroup() string

GetTimeTagGroup 获取当前日期字符串,结果:2024:05

func GetTimeUnix

func GetTimeUnix(t time.Time) int64

GetTimeUnix 转为时间戳->秒数

func GetUserAgent

func GetUserAgent(ctx context.Context) string

GetUserAgent 获取user-agent

func GetWeekDay

func GetWeekDay() (string, string)

GetWeekDay 获取本周的开始时间和结束时间

func InArray

func InArray(target string, strArray []string) bool

InArray 判断字符串是否存在数组中

func IpInBlackListRange

func IpInBlackListRange(ip string, ipList []string) (result bool)

IpInBlackListRange 判断IP是否在黑名单

func IsSameDay

func IsSameDay(t1, t2 int64) bool

IsSameDay 是否为同一天

func IsSameMinute

func IsSameMinute(t1, t2 int64) bool

IsSameMinute 是否为同一分钟

func ParseFilePath

func ParseFilePath(pathStr string) (fileName string, fileType string)

ParseFilePath 解析路径获取文件名称及后缀

func ParseIpRange

func ParseIpRange(cidr string) ([]string, error)

ParseIpRange 用于将以 "," 分割的多个 CIDR 范围字符串解析为 CIDR 数组。 如果一个 CIDR 范围是以 "-" 分割的两个 IP 地址,那么我们会使用 binaryToInt 和 intToIP 函数将它们转换为整数并再次转换为 CIDR 字符串, 并将其加入到 CIDR 数组中。

func ParsePrivateKeyFromPEM

func ParsePrivateKeyFromPEM(pemBytes []byte) (privateKey *rsa.PrivateKey, err error)

ParsePrivateKeyFromPEM 从 PEM 格式的字节切片中解析 RSA 私钥

func ParsePublicKeyFromPEM

func ParsePublicKeyFromPEM(pemBytes []byte) (publicKey *rsa.PublicKey, err error)

ParsePublicKeyFromPEM 从 PEM 格式的字节切片中解析 RSA 公钥

func ReadBlock

func ReadBlock(filePath string)

文件一块一块的读取

func ReadZipFileByFileName

func ReadZipFileByFileName(file *ghttp.UploadFile, fileName string) (result map[string]interface{}, err error)

ReadZipFileByFileName 读取压缩包指定文件内容

func RemoveDuplicationMap

func RemoveDuplicationMap(arr []string) []string

RemoveDuplicationMap 数组去重

func RemoveRepeatedElementAndEmpty

func RemoveRepeatedElementAndEmpty(arr []int) []int

func ReplaceTemplate

func ReplaceTemplate(content string, variable map[string]interface{}) (result string, err error)

func ReverseRead

func ReverseRead(name string, lineNum uint) ([]string, error)

func ReverseReadLines

func ReverseReadLines(name string) ([]string, error)

ReverseReadLines 从文件末尾开始逆序高效地读取行。

func SavePrivateKeyToFile

func SavePrivateKeyToFile(privateKey *rsa.PrivateKey, filename string) (err error)

SavePrivateKeyToFile 将 RSA 私钥保存到文件

func SavePublicKeyToFile

func SavePublicKeyToFile(publicKey *rsa.PublicKey, filename string) (err error)

SavePublicKeyToFile 将 RSA 公钥保存到文件

func ShouldExclude

func ShouldExclude(filename string, excludeList []string) bool

func UploadZip

func UploadZip(file *ghttp.UploadFile, zipPath string, excludeFiles []string) (err error)

UploadZip 上传ZIP包

func ValidatePassword

func ValidatePassword(password string, minimumLength int, requireComplexity int, requireDigit int, requireLowercase int, requireUppercase int) (flag bool, err error)

func WalkDir

func WalkDir(dirname string) ([]fileInfo, error)

WalkDir 获取目录下文件的名称和大小

func WriteToFile

func WriteToFile(fileName string, content string) error

WriteToFile 写入文件

Types

This section is empty.

Jump to

Keyboard shortcuts

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