main.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package main
  2. import (
  3. "Wx_MP/Nats"
  4. "Wx_MP/Server"
  5. "Wx_MP/conf"
  6. "Wx_MP/logs"
  7. _ "Wx_MP/routers"
  8. beego "github.com/beego/beego/v2/server/web"
  9. "github.com/beego/beego/v2/server/web/filter/cors"
  10. "strconv"
  11. "time"
  12. )
  13. func init() {
  14. // 定时 更新 微信AccessToke
  15. go func() {
  16. for true {
  17. logs.Println("================ 定时更新 GetAccessToken =================")
  18. Server.GetAccessToken(true)
  19. time.Sleep(10 * time.Minute)
  20. }
  21. }()
  22. Nats.NatsInit()
  23. }
  24. func main() {
  25. HTTPPort_int, _ := strconv.Atoi(conf.HTTPPort)
  26. beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
  27. AllowAllOrigins: true,
  28. AllowMethods: []string{"*"},
  29. AllowHeaders: []string{"Origin", "Authorization", "Access-Control-Allow-Origin"},
  30. ExposeHeaders: []string{"Content-Length", "Access-Control-Allow-Origin"},
  31. AllowCredentials: true,
  32. }))
  33. beego.BConfig.AppName = conf.AppName // 项目名
  34. beego.BConfig.ServerName = conf.AppName + conf.HTTPPort //server 名称
  35. beego.BConfig.RunMode = "dev" // 应用的运行模式
  36. beego.BConfig.Listen.HTTPPort = HTTPPort_int //监听端口 本地:8518 线上:8528
  37. logs.Println("======= beego.Run ======")
  38. beego.Run()
  39. }