12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- package main
- import (
- _ "filter"
- "fmt"
- "front"
- "github.com/donnie4w/go-logger/logger"
- "github.com/go-xweb/xweb"
- "io/ioutil"
- "log"
- "os"
- qu "qfw/util"
- "regexp"
- sp "spiderutil"
- "time"
- . "udptask"
- "util"
- )
- var timeReg = regexp.MustCompile("[0-9]{4}-[0-9]{2}-[0-9]{2}")
- func init() {
- qu.ReadConfig(&sp.Config) //初始化配置
- util.InitMgoPool() //初始化连接
- util.InitOther()
- InitUdp()
- //xweb框架配置
- xweb.Config.RecoverPanic = true
- xweb.Config.Profiler = true
- xweb.RootApp().AppConfig.TemplateDir = "web/templates"
- xweb.RootApp().AppConfig.StaticDir = "web/res"
- xweb.RootApp().AppConfig.StaticFileVersion = false
- xweb.RootApp().AppConfig.CheckXsrf = false
- xweb.RootApp().AppConfig.ReloadTemplates = true
- xweb.RootApp().AppConfig.EnableHttpCache = false
- xweb.RootApp().AppConfig.Mode = xweb.Product
- xweb.RootApp().AppConfig.CacheTemplates = false
- xweb.AddAction(&front.Front{})
- xweb.RootApp().AppConfig.SessionTimeout = 1 * time.Hour
- xweb.RootApp().Logger.SetOutputLevel(4)
- //日志
- logger.SetRollingDaily("./logs", "spider.log")
- }
- func main() {
- go clearLogs()
- go CheckMapJob()
- log.Println("Web Port:", sp.Config.Webport)
- xweb.Run(":" + sp.Config.Webport)
- }
- func clearLogs() {
- fmt.Println("=======clearLogs========")
- timeInt := time.Now().AddDate(0, 0, -30).Unix()
- dirs, err := ioutil.ReadDir("./logs")
- if err == nil {
- for _, f := range dirs {
- fname := f.Name()
- logTimeStr := timeReg.FindString(fname)
- if logTimeStr == "" {
- continue
- }
- logTimeInt, _ := time.ParseInLocation("2006-01-02", logTimeStr, time.Local)
- if logTimeInt.Unix() < timeInt {
- os.Remove("./logs/" + fname)
- }
- }
- }
- time.AfterFunc(24*time.Hour, clearLogs)
- }
|