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:
@@ -4,11 +4,9 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
||||
"with_you/internal/model"
|
||||
redisclient "with_you/internal/pkg/redis"
|
||||
@@ -501,51 +499,3 @@ func (s *sensitiveServiceImpl) loadFromRedis(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ==================== 辅助函数 ====================
|
||||
|
||||
// ContainsSensitiveWord 快速检查文本是否包含敏感词
|
||||
func ContainsSensitiveWord(text string, tree *SensitiveWordTree) bool {
|
||||
if tree == nil || text == "" {
|
||||
return false
|
||||
}
|
||||
hasSensitive, _ := tree.Check(text)
|
||||
return hasSensitive
|
||||
}
|
||||
|
||||
// FilterSensitiveWords 过滤敏感词并返回替换后的文本
|
||||
func FilterSensitiveWords(text string, tree *SensitiveWordTree, repl string) string {
|
||||
if tree == nil || text == "" {
|
||||
return text
|
||||
}
|
||||
if repl == "" {
|
||||
repl = "***"
|
||||
}
|
||||
return tree.Replace(text, repl)
|
||||
}
|
||||
|
||||
// ValidateTextLength 验证文本长度是否合法
|
||||
func ValidateTextLength(text string, minLen, maxLen int) bool {
|
||||
length := utf8.RuneCountInString(text)
|
||||
return length >= minLen && length <= maxLen
|
||||
}
|
||||
|
||||
// SanitizeText 清理文本,移除多余空白字符
|
||||
func SanitizeText(text string) string {
|
||||
// 替换多个连续空白字符为单个空格
|
||||
spaceReg := regexp.MustCompile(`\s+`)
|
||||
text = spaceReg.ReplaceAllString(text, " ")
|
||||
// 去除首尾空白
|
||||
return strings.TrimSpace(text)
|
||||
}
|
||||
|
||||
// ==================== 默认敏感词列表 ====================
|
||||
|
||||
// DefaultSensitiveWords 返回默认敏感词列表(示例)
|
||||
func DefaultSensitiveWords() map[string]struct{} {
|
||||
return map[string]struct{}{
|
||||
// 示例敏感词,实际需要从数据库或配置加载
|
||||
"测试敏感词1": {},
|
||||
"测试敏感词2": {},
|
||||
"测试敏感词3": {},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user