main.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package main
  2. import (
  3. _ "filter"
  4. "fmt"
  5. "front"
  6. "github.com/donnie4w/go-logger/logger"
  7. "github.com/go-xweb/xweb"
  8. "io/ioutil"
  9. "log"
  10. "os"
  11. qu "qfw/util"
  12. "regexp"
  13. sp "spiderutil"
  14. "time"
  15. . "udptask"
  16. "util"
  17. )
  18. var timeReg = regexp.MustCompile("[0-9]{4}-[0-9]{2}-[0-9]{2}")
  19. func init() {
  20. qu.ReadConfig(&sp.Config) //初始化配置
  21. util.InitMgoPool() //初始化连接
  22. util.InitOther()
  23. InitUdp()
  24. //xweb框架配置
  25. xweb.Config.RecoverPanic = true
  26. xweb.Config.Profiler = true
  27. xweb.RootApp().AppConfig.TemplateDir = "web/templates"
  28. xweb.RootApp().AppConfig.StaticDir = "web/res"
  29. xweb.RootApp().AppConfig.StaticFileVersion = false
  30. xweb.RootApp().AppConfig.CheckXsrf = false
  31. xweb.RootApp().AppConfig.ReloadTemplates = true
  32. xweb.RootApp().AppConfig.EnableHttpCache = false
  33. xweb.RootApp().AppConfig.Mode = xweb.Product
  34. xweb.RootApp().AppConfig.CacheTemplates = false
  35. xweb.AddAction(&front.Front{})
  36. xweb.RootApp().AppConfig.SessionTimeout = 1 * time.Hour
  37. xweb.RootApp().Logger.SetOutputLevel(4)
  38. //日志
  39. logger.SetRollingDaily("./logs", "spider.log")
  40. }
  41. func main() {
  42. go clearLogs()
  43. go CheckMapJob()
  44. log.Println("Web Port:", sp.Config.Webport)
  45. xweb.Run(":" + sp.Config.Webport)
  46. }
  47. func clearLogs() {
  48. fmt.Println("=======clearLogs========")
  49. timeInt := time.Now().AddDate(0, 0, -30).Unix()
  50. dirs, err := ioutil.ReadDir("./logs")
  51. if err == nil {
  52. for _, f := range dirs {
  53. fname := f.Name()
  54. logTimeStr := timeReg.FindString(fname)
  55. if logTimeStr == "" {
  56. continue
  57. }
  58. logTimeInt, _ := time.ParseInLocation("2006-01-02", logTimeStr, time.Local)
  59. if logTimeInt.Unix() < timeInt {
  60. os.Remove("./logs/" + fname)
  61. }
  62. }
  63. }
  64. time.AfterFunc(24*time.Hour, clearLogs)
  65. }