This commit performs a significant cleanup of the codebase by removing unused functions, methods, and entire files across various internal modules. This reduces technical debt and simplifies the project structure. Key changes include: - **cache**: Removed unused cache key generators and metrics snapshots. - **dto**: Removed redundant converter functions and segment creation helpers. - **middleware**: Deleted the unused `logger.go` middleware and simplified `ratelimit.go` and `casbin.go`. - **model**: Removed unused ID helpers, database closing functions, and batch decryption logic. - **pkg**: Cleaned up unused utility functions in `circuitbreaker`, `crypto`, `cursor`, `hook`, and `utils`. - **service**: Deleted `account_cleanup_service.go` and removed unused helper functions in `log_cleanup_service.go` and `sensitive_service.go`. - **repository**: Removed unused private loading methods in `comment_repo.go`.
53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
package utils
|
|
|
|
import (
|
|
"regexp"
|
|
)
|
|
|
|
// ValidateEmail 验证邮箱
|
|
func ValidateEmail(email string) bool {
|
|
pattern := `^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$`
|
|
matched, _ := regexp.MatchString(pattern, email)
|
|
return matched
|
|
}
|
|
|
|
// ValidateUsername 验证用户名
|
|
func ValidateUsername(username string) bool {
|
|
if len(username) < 3 || len(username) > 30 {
|
|
return false
|
|
}
|
|
pattern := `^[a-zA-Z0-9_]+$`
|
|
matched, _ := regexp.MatchString(pattern, username)
|
|
return matched
|
|
}
|
|
|
|
// ValidatePassword 验证密码强度
|
|
func ValidatePassword(password string) bool {
|
|
if len(password) < 8 || len(password) > 50 {
|
|
return false
|
|
}
|
|
|
|
var hasUpper, hasLower, hasDigit bool
|
|
for _, c := range password {
|
|
switch {
|
|
case 'A' <= c && c <= 'Z':
|
|
hasUpper = true
|
|
case 'a' <= c && c <= 'z':
|
|
hasLower = true
|
|
case '0' <= c && c <= '9':
|
|
hasDigit = true
|
|
}
|
|
}
|
|
|
|
return hasUpper && hasLower && hasDigit
|
|
}
|
|
|
|
|
|
// ValidatePhone 验证手机号
|
|
func ValidatePhone(phone string) bool {
|
|
pattern := `^1[3-9]\d{9}$`
|
|
matched, _ := regexp.MatchString(pattern, phone)
|
|
return matched
|
|
}
|
|
|