main.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package main
  2. import (
  3. "Cold_mqtt/MqttServer"
  4. "Cold_mqtt/Nats"
  5. "Cold_mqtt/Plugins"
  6. "Cold_mqtt/TimeTask"
  7. "Cold_mqtt/conf"
  8. "Cold_mqtt/logs"
  9. _ "Cold_mqtt/routers"
  10. "github.com/beego/beego/v2/adapter/orm"
  11. beego "github.com/beego/beego/v2/server/web"
  12. _ "github.com/go-sql-driver/mysql"
  13. "strconv"
  14. )
  15. func init() {
  16. println("--------------- go --------------")
  17. orm.RegisterDriver("mysql", orm.DRMySQL)
  18. orm.RegisterDataBase("default", "mysql",
  19. conf.MysqlServer_Username+":"+conf.MysqlServer_Password+"@tcp("+conf.MysqlServer_UrlPort+")/"+conf.MysqlServer_Database+"?charset=utf8mb4&loc=Local&parseTime=True",
  20. conf.MysqlServer_MaxIdleConnections, conf.MysqlServer_MaxOpenConnections)
  21. orm.RunSyncdb("default", false, true) // 创建数据库
  22. //logs.Println("MysqlServer:" + conf.MysqlServer_Username + ":" + conf.MysqlServer_Password + "@tcp(" + conf.MysqlServer_UrlPort + ")/" + conf.MysqlServer_Database + "?charset=utf8mb4&loc=Local&parseTime=True")
  23. }
  24. func main() {
  25. beego.BConfig.AppName = conf.AppName + "_" + strconv.Itoa(conf.HTTPPort) // 项目名
  26. beego.BConfig.ServerName = conf.AppName + "_" + strconv.Itoa(conf.HTTPPort) //server 名称
  27. beego.BConfig.RunMode = "dev" // 应用的运行模式
  28. beego.BConfig.Listen.HTTPPort = conf.HTTPPort //监听端口 本地:8518 线上:8528
  29. logs.Println("MqttServer", " ======= 项目启动 ========")
  30. go MqttServer.Run_MqttServer() // MQTT 通讯
  31. ////go MqttServer.MqttPolling() // MQTT 设备轮询
  32. go MqttServer.DeviceMqttMap_go() //// 缓存数据发送-确保设备在休眠后 能收到数据
  33. go Nats.NatsInit() // Nats 通讯
  34. go TimeTask.Init() // 时间任务
  35. go Plugins.ContinuousPushOfOfflineDeviceWarning() //设备离线报警连续推送
  36. beego.Run()
  37. }