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:
@@ -1,7 +1,6 @@
|
||||
package crypto
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"sync"
|
||||
)
|
||||
|
||||
@@ -75,35 +74,3 @@ func (e *MessageEncryptor) BatchDecrypt(ciphertexts []string, workerCount int) [
|
||||
return results
|
||||
}
|
||||
|
||||
// DecryptMessageSegments 解密消息段 JSON
|
||||
// 这是一个便捷方法,直接返回解析后的 MessageSegments
|
||||
func (e *MessageEncryptor) DecryptMessageSegments(ciphertext string) ([]byte, error) {
|
||||
if e == nil || ciphertext == "" {
|
||||
return nil, nil
|
||||
}
|
||||
return e.Decrypt(ciphertext)
|
||||
}
|
||||
|
||||
// TryParseMessageSegments 尝试解析消息段
|
||||
// 先尝试解密,如果失败则尝试直接解析(兼容未加密的旧数据)
|
||||
func TryParseMessageSegments(ciphertext string, segments any) error {
|
||||
if ciphertext == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
encryptor := GetMessageEncryptor()
|
||||
if encryptor == nil {
|
||||
// 加密器未初始化,直接解析
|
||||
return json.Unmarshal([]byte(ciphertext), segments)
|
||||
}
|
||||
|
||||
// 尝试解密
|
||||
plaintext, err := encryptor.Decrypt(ciphertext)
|
||||
if err != nil {
|
||||
// 解密失败,可能是未加密的旧数据,尝试直接解析
|
||||
return json.Unmarshal([]byte(ciphertext), segments)
|
||||
}
|
||||
|
||||
// 解析解密后的数据
|
||||
return json.Unmarshal(plaintext, segments)
|
||||
}
|
||||
|
||||
@@ -167,7 +167,3 @@ func (e *MessageEncryptor) RotateKey(newKey string, newVersion int) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// IsInitialized 检查加密器是否已初始化
|
||||
func IsInitialized() bool {
|
||||
return globalEncryptor != nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user