zhangzengfei
2024-07-23 a3a24e1cf44aa4e95a8684c86455a2b7064ac623
定时删除本地存储的图片
1个文件已修改
29 ■■■■■ 已修改文件
service/clean.go 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/clean.go
@@ -1,6 +1,14 @@
package service
import "gat1400Exchange/models"
import (
    "os"
    "path"
    "path/filepath"
    "time"
    "gat1400Exchange/config"
    "gat1400Exchange/models"
)
func CleanExpireData() {
    var pos models.Positions
@@ -8,4 +16,23 @@
    var cache models.Cache
    cache.Clean()
    if config.ClientConf.UploadType == "url" {
        imagePath := path.Join(config.LogConf.Path, "gat1400_face_images")
        deleteOldFolders(imagePath)
    }
}
func deleteOldFolders(root string) error {
    return filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
        if err != nil {
            return err
        }
        if info.IsDir() && time.Now().Sub(info.ModTime()) > 24*time.Hour {
            return os.RemoveAll(path)
        }
        return nil
    })
}