2024-08-30 18:02:15 +08:00
|
|
|
|
package utils
|
|
|
|
|
|
|
|
|
|
import (
|
2024-11-14 18:33:56 +08:00
|
|
|
|
"crypto/md5"
|
|
|
|
|
"encoding/hex"
|
2024-08-30 18:02:15 +08:00
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
2024-11-14 18:33:56 +08:00
|
|
|
|
"regexp"
|
|
|
|
|
"strings"
|
2024-08-30 18:02:15 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Load 获取插件目录中的文件信息
|
|
|
|
|
func Load(dir string) ([]string, error) {
|
|
|
|
|
entries, err := os.ReadDir(dir)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("读取目录错误:%w", err)
|
|
|
|
|
}
|
|
|
|
|
files := make([]string, 0, len(entries))
|
|
|
|
|
for _, entry := range entries {
|
|
|
|
|
info, err := entry.Info()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("获取文件信息错误:%w", err)
|
|
|
|
|
}
|
|
|
|
|
if !info.IsDir() {
|
|
|
|
|
files = append(files, fmt.Sprintf("%s/%s", dir, info.Name()))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return files, nil
|
|
|
|
|
}
|
2024-11-14 18:33:56 +08:00
|
|
|
|
|
|
|
|
|
func Md5(values []byte) string {
|
|
|
|
|
hash := md5.Sum(values)
|
|
|
|
|
return strings.ToUpper(hex.EncodeToString(hash[:]))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IsPhoneNumber 检查给定的字符串是否为有效的手机号码
|
|
|
|
|
func IsPhoneNumber(phoneNumber string) bool {
|
|
|
|
|
phoneRegex := `^1[34578]\d{9}$`
|
|
|
|
|
return regexp.MustCompile(phoneRegex).MatchString(phoneNumber)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IsEmail 检查给定的字符串是否为有效的电子邮箱地址
|
|
|
|
|
func IsEmail(email string) bool {
|
|
|
|
|
var emailRegex = regexp.MustCompile(`[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$`)
|
|
|
|
|
return emailRegex.MatchString(email)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IsValidQQ 检查给定的字符串是否为有效的 QQ 号
|
|
|
|
|
func IsValidQQ(qq string) bool {
|
|
|
|
|
// QQ号正则表达式:5到11位数字,且开头不为0的情况
|
|
|
|
|
re := regexp.MustCompile(`^(?!0)[0-9]{5,11}$`)
|
|
|
|
|
return re.MatchString(qq)
|
|
|
|
|
}
|