You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-fly/controller/timer.go

41 lines
855 B

//+build !linux
package controller
import (
"github.com/taoshihan1991/imaptool/config"
"os"
"path/filepath"
"runtime"
"syscall"
"time"
)
5 years ago
var osType = runtime.GOOS
5 years ago
const expireTime = 30 * 60
//检测权限文件是否过期,超过30分钟删除掉
5 years ago
func TimerSessFile() {
go func() {
for {
5 years ago
time.Sleep(time.Second * 10)
files, _ := filepath.Glob(config.Dir + "sess_*")
for _, file := range files {
fileInfo, _ := os.Stat(file)
var createTime int64
5 years ago
now := time.Now().Unix()
if osType == "windows" {
wFileSys := fileInfo.Sys().(*syscall.Win32FileAttributeData)
5 years ago
tNanSeconds := wFileSys.CreationTime.Nanoseconds() /// 返回的是纳秒
createTime = tNanSeconds / 1e9 ///秒
}
5 years ago
diffTime := now - createTime
if diffTime > expireTime {
os.Remove(file)
}
}
}
}()
}