refactor: cleanup unused code and simplify internal packages
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`.
This commit is contained in:
@@ -2,7 +2,6 @@ package utils
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// ValidateEmail 验证邮箱
|
||||
@@ -43,39 +42,6 @@ func ValidatePassword(password string) bool {
|
||||
return hasUpper && hasLower && hasDigit
|
||||
}
|
||||
|
||||
// ValidatePasswordWithDetail 验证密码强度并返回详细信息
|
||||
func ValidatePasswordWithDetail(password string) (bool, string) {
|
||||
if len(password) < 8 {
|
||||
return false, "密码长度至少8位"
|
||||
}
|
||||
if len(password) > 50 {
|
||||
return false, "密码长度不能超过50位"
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
if !hasUpper {
|
||||
return false, "密码必须包含大写字母"
|
||||
}
|
||||
if !hasLower {
|
||||
return false, "密码必须包含小写字母"
|
||||
}
|
||||
if !hasDigit {
|
||||
return false, "密码必须包含数字"
|
||||
}
|
||||
|
||||
return true, ""
|
||||
}
|
||||
|
||||
// ValidatePhone 验证手机号
|
||||
func ValidatePhone(phone string) bool {
|
||||
@@ -84,13 +50,3 @@ func ValidatePhone(phone string) bool {
|
||||
return matched
|
||||
}
|
||||
|
||||
// SanitizeHTML 清理HTML,防止XSS攻击
|
||||
func SanitizeHTML(input string) string {
|
||||
input = strings.ReplaceAll(input, "&", "&")
|
||||
input = strings.ReplaceAll(input, "<", "<")
|
||||
input = strings.ReplaceAll(input, ">", ">")
|
||||
input = strings.ReplaceAll(input, "\"", """)
|
||||
input = strings.ReplaceAll(input, "'", "'")
|
||||
input = strings.ReplaceAll(input, "/", "/")
|
||||
return input
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user