main.go 1.8 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. orm.RegisterDriver("mysql", orm.DRMySQL)
  17. orm.RegisterDataBase("default", "mysql",
  18. conf.MysqlServer_Username+":"+conf.MysqlServer_Password+"@tcp("+conf.MysqlServer_UrlPort+")/"+conf.MysqlServer_Database+"?charset=utf8mb4&loc=Local&parseTime=True",
  19. conf.MysqlServer_MaxIdleConnections, conf.MysqlServer_MaxOpenConnections)
  20. orm.RunSyncdb("default", false, true) // 创建数据库
  21. //logs.Println("MysqlServer:" + conf.MysqlServer_Username + ":" + conf.MysqlServer_Password + "@tcp(" + conf.MysqlServer_UrlPort + ")/" + conf.MysqlServer_Database + "?charset=utf8mb4&loc=Local&parseTime=True")
  22. }
  23. func main() {
  24. beego.BConfig.AppName = conf.AppName + "_" + strconv.Itoa(conf.HTTPPort) // 项目名
  25. beego.BConfig.ServerName = conf.AppName + "_" + strconv.Itoa(conf.HTTPPort) //server 名称
  26. beego.BConfig.RunMode = "dev" // 应用的运行模式
  27. beego.BConfig.Listen.HTTPPort = conf.HTTPPort //监听端口 本地:8518 线上:8528
  28. logs.Println("MqttServer", " ======= 项目启动 ========")
  29. go MqttServer.Run_MqttServer() // MQTT 通讯
  30. ////go MqttServer.MqttPolling() // MQTT 设备轮询
  31. go MqttServer.DeviceMqttMap_go() //// 缓存数据发送-确保设备在休眠后 能收到数据
  32. go Nats.NatsInit() // Nats 通讯
  33. go TimeTask.Init() // 时间任务
  34. go Plugins.ContinuousPushOfOfflineDeviceWarning() //设备离线报警连续推送
  35. beego.Run()
  36. }