Documentation
¶
Overview ¶
Package mooonutils Wrote by yijian on 2025/06/14
Package mooonutils Wrote by yijian on 2024/10/22
Package mooonutils Wrote by yijian on 2024/01/02
Package mooonutils Wrote by yijian on 2024/10/25
Package mooonutils Wrote by yijian on 2024/01/02
Index ¶
- func ConvertDateFormat(dateStr string) string
- func CopyFile(src, dst string, overwrite bool) error
- func CountUtf8Characters(utf8Str string) int
- func DeleteFile(path string) error
- func DesensitizeChineseName(name string, m, n int) string
- func DesensitizeUtf8Str(str string, m, n int) string
- func ExtractFilenameWithoutExtension(path string) string
- func ExtractUrlPath(urlStr string) string
- func GenerateResidentIdentityCardNumber(areaCode string, birthDate string, sequence int) (string, error)
- func GetCurrentTimestamp(timezone string) int64
- func GetCurrentTimestampString(timezone string) string
- func GetExpirationDays(startTime, now time.Time, days int) int
- func GetExpirationTime(startTime time.Time, days int) time.Time
- func GetFilesBySuffix(dirPath string, suffixes []string) ([]string, error)
- func GetHexNonceStr(length int) string
- func GetLowercaseNonceStr(length int) string
- func GetNonceStr(length int) string
- func GetProgramDir() (string, error)
- func GetUppercaseNonceStr(length int) string
- func IsELF(header []byte) bool
- func IsExecutableFile(filepath string) (bool, error)
- func IsMachO(header []byte) bool
- func IsPE(header []byte) bool
- func IsResidentIdentityCardNumber(id string) bool
- func IsValidBirthdate(date string) bool
- func IsValidTime(s string) bool
- func Md5File(filePath string) (string, error)
- func NormalizeDateTimeString(str string, withHms bool) string
- func PathExists(path string) (bool, bool, error)
- func String2Time(dateStr string) (time.Time, error)
- func TruncateUtf8String(utf8Str string, maxCharCount int) string
- func Unzip(zipFile, destDir string, options ...bool) ([]string, error)
- func ZipDir(zipFilePath, srcDir string) error
- func ZipDirEx(zipFilePath, srcDir string) error
- func ZipFiles(zipFilePath string, srcFilePaths []string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertDateFormat ¶ added in v0.0.16
ConvertDateFormat 将 YYYY-MM-DD 格式的日期转换为 YYYYMMDD 格式
func CountUtf8Characters ¶
CountUtf8Characters 计算字数,一个数字、字母和汉字都分别计 1
func DesensitizeChineseName ¶ added in v0.0.61
DesensitizeChineseName 脱敏中文姓名(安全版本) name 中文姓名,少数民族的姓名中间可能有点号 m 保留的前 m 个字 n 保留的后 n 个字
func DesensitizeUtf8Str ¶ added in v0.0.61
DesensitizeUtf8Str 功能保持不变,直接复用通用逻辑
func ExtractFilenameWithoutExtension ¶ added in v0.0.22
ExtractFilenameWithoutExtension 提取不含后缀的文件名
func ExtractUrlPath ¶ added in v0.0.15
ExtractUrlPath 提取 url 路径
func GenerateResidentIdentityCardNumber ¶ added in v0.0.12
func GenerateResidentIdentityCardNumber(areaCode string, birthDate string, sequence int) (string, error)
GenerateResidentIdentityCardNumber 生成有效的居民身份证号,最后一位是根据前17位计算得出的校验码 areaCode 六位数字行政区划代码,如:440306 birthDate 八位数字出生日期,如:20240529 sequence 三位顺序码,奇数分配给男性,偶数分配给女性
func GetCurrentTimestamp ¶
GetCurrentTimestamp 获取指定时区的当前时间戳
func GetExpirationDays ¶ added in v0.0.42
GetExpirationDays 计算当前时间到截止时间间的天数 startTime 起始时间 now 当前时间 days 从 startTime 开始的有效天数,截止日期那天的最后一秒 返回值:剩余的天数,0 表示已过期,负数表示已过期的天数
func GetExpirationTime ¶ added in v0.0.42
GetExpirationTime 取得过期时间 startTime 起始时间 days 从 startTime 开始的有效天数,截止日期那天的最后一秒 返回值:截止日期那天的最后一秒
func GetFilesBySuffix ¶ added in v0.0.52
GetFilesBySuffix 获取指定目录下指定后缀的文件,结构存放到字符串数组中
func GetHexNonceStr ¶
func GetLowercaseNonceStr ¶
func GetNonceStr ¶
func GetUppercaseNonceStr ¶
func IsExecutableFile ¶ added in v0.0.36
IsExecutableFile 判断 filepath 是否为一个可执行的程序文件
func IsResidentIdentityCardNumber ¶
IsResidentIdentityCardNumber 判断是否为居民身份证号
func IsValidTime ¶ added in v0.0.18
func NormalizeDateTimeString ¶ added in v0.0.21
NormalizeDateTimeString 将中文日期或时间字符串规整为“YYYY-MM-DD hh:mm:ss”格式 返回的不一定就是有效的时间格式,应当在调用 IsValidTime 函数时进行进一步验证 withHms 参数 str 的值是否包含了"时、分、秒",当值为 true 时,如果 str 本身不含时分秒,则结果会自动添加上 str 日期或者时间字符串,格式可为: 1)YYYY年MM月DD日 hh时mm分ss秒 2)YYYY年MM月DD日hh时mm分ss秒 3)YYYY年MM月DD日 4)YYYY-MM-DD hh:mm:ss 5)YYYY-MM-DD 6)YYYY/MM/DD hh:mm:ss 7)YYYY/MM/DD 8)YYYYMMDD 9)YYYY-MM-DDhh:mm:ss
func PathExists ¶ added in v0.0.52
PathExists 判断路径是否存在 返回:是否存在exists、是否为目录isDir、错误err
func String2Time ¶
String2Time 将日期字符串转换为时间对象 如果 dateStr 为"YYYY年MM月DD日"格式,可将"年、月、日"替换为"-"后再调用此函数
func TruncateUtf8String ¶
TruncateUtf8String 截取 UTF8 字符串,使其字数(不是字节数,一个数字、字母和汉字都分别计 1)不超过 maxCharCount
func Unzip ¶ added in v0.0.18
Unzip 解压 zip 文件 返回值:解压后的文件(含目录部分,如果是当前目录“.”则仅文件名)列表 options[0]:是否覆盖解压后的同名文件,默认是 true options[1]:返回结果是否忽略目录,仅包含文件,默认是 true destDir:解压后文件的存放目录,如果不存在会自动创建
func ZipDir ¶ added in v0.0.51
ZipDir 压缩指定目录到ZIP zipFilePath: 生成的ZIP文件路径 srcDir: 需要压缩的目录,不含子目录及子目录下的文件
Types ¶
This section is empty.