refactor(backend): 修改App结构体并调整互斥锁使用

将App.FilePath字段改为可序列化以便服务器重启后恢复
将saveApps函数中的RLock改为Lock以确保数据一致性
清理未使用的文档文件
This commit is contained in:
2025-12-25 14:12:02 +08:00
parent 4fb50e6b56
commit 20ccfbc205
8 changed files with 5 additions and 270 deletions

View File

@@ -1 +1,3 @@
[
]

View File

@@ -22,7 +22,7 @@ type App struct {
Name string `json:"name"`
FileName string `json:"fileName"`
Date string `json:"date"`
FilePath string `json:"-"` // 内部使用,不序列化
FilePath string `json:"filePath"` // 序列化到JSON中用于服务器重启后恢复
}
type Doc struct {
DocBody string `json:"docBody"`
@@ -72,8 +72,8 @@ func loadApps() {
// 保存apps数据
func saveApps() error {
appsMutex.RLock()
defer appsMutex.RUnlock()
appsMutex.Lock()
defer appsMutex.Unlock()
file, err := os.Create(jsonFile)
if err != nil {