main.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package main
  2. import (
  3. "Yunlot/Nats"
  4. _ "Yunlot/Nats"
  5. "Yunlot/Plugin"
  6. "Yunlot/RunCode"
  7. "Yunlot/TimeTask"
  8. "Yunlot/conf"
  9. "Yunlot/logs"
  10. _ "Yunlot/routers"
  11. "github.com/beego/beego/v2/adapter/orm"
  12. orm2 "github.com/beego/beego/v2/client/orm"
  13. beego "github.com/beego/beego/v2/server/web"
  14. _ "github.com/go-sql-driver/mysql"
  15. "strconv"
  16. )
  17. func init() {
  18. logs.Println("MysqlServer:" + conf.MysqlServer_Username + ":" + conf.MysqlServer_Password + "@tcp(" + conf.MysqlServer_UrlPort + ")/" + conf.MysqlServer_Database + "?charset=utf8mb4&loc=Local&parseTime=True")
  19. orm.RegisterDriver("mysql", orm.DRMySQL)
  20. orm.RegisterDataBase("default", "mysql",
  21. conf.MysqlServer_Username+":"+conf.MysqlServer_Password+"@tcp("+conf.MysqlServer_UrlPort+")/"+conf.MysqlServer_Database+"?charset=utf8mb4&loc=Local&parseTime=True",
  22. conf.MysqlServer_MaxIdleConnections, conf.MysqlServer_MaxOpenConnections)
  23. orm.RunSyncdb("default", false, true) // 创建数据库
  24. }
  25. func main() {
  26. beego.BConfig.AppName = conf.AppName + "_" + strconv.Itoa(conf.HTTPPort) // 项目名
  27. beego.BConfig.ServerName = conf.AppName + "_" + strconv.Itoa(conf.HTTPPort) //server 名称
  28. beego.BConfig.RunMode = "dev" // 应用的运行模式
  29. beego.BConfig.Listen.HTTPPort = conf.HTTPPort //监听端口 本地:8518 线上:8528
  30. orm2.Debug = true
  31. logs.Println("MqttServer", " ======= 项目启动 ========")
  32. //go MqttServer2.Run_MqttServer() // MQTT 通讯
  33. //go MqttServer.MqttPolling() // MQTT 设备轮询
  34. //go MqttServer.DeviceMqttMap_go() //// 缓存数据发送-确保设备在休眠后 能收到数据
  35. // MQTT 通讯
  36. //if conf.MqttServer_Open == 1 {
  37. // mode := Product.ProductMode{
  38. // Id: 1,
  39. // T_name: "MQTT",
  40. // T_address: fmt.Sprintf("mqtt://%s", conf.MqttServer_Url),
  41. // T_describe: "MQTT 接入方式为设备和云平台提供双向连接,设备既可上报属性数据,也可接收云端的消息下发。",
  42. // T_state: 1,
  43. // }
  44. // Product.ProductModeAdd(mode)
  45. // go MqttServer.Run_MqttServer()
  46. //}
  47. //// TCP 通讯
  48. //if conf.TCPServer_Open == 1 {
  49. // mode := Product.ProductMode{
  50. // Id: 2,
  51. // T_name: "TCP",
  52. // T_address: fmt.Sprintf("TCP:%d", conf.TCPServer_Port),
  53. // T_describe: "TCP 接入方式为设备和云平台提供双向连接,设备既可上报属性数据,也可接收云端的消息下发。",
  54. // T_state: 1,
  55. // }
  56. // Product.ProductModeAdd(mode)
  57. // go TcpServer.TcpServer()
  58. //}
  59. //// HTTP 通讯
  60. //if conf.HTTPServer_Open == 1 {
  61. // mode := Product.ProductMode{
  62. // Id: 6,
  63. // T_name: "HTTP",
  64. // T_address: fmt.Sprintf("http://:%d", conf.HTTPServer_Port),
  65. // T_describe: "HTTP 接入方式为设备和云平台提供双向连接,设备既可上报属性数据,也可接收云端的消息下发。",
  66. // T_state: 1,
  67. // }
  68. // Product.ProductModeAdd(mode)
  69. // go HttpServer.Run()
  70. //}
  71. //go Nats.NatsInit() // Nats 通讯
  72. go TimeTask.Init() // 时间任务
  73. go RunCode.RunCode_Inte() // 代码编译
  74. go Nats.Nats_Server_init() // 内部 Nats 通讯
  75. go Plugin.PluginInit() // Plugin 初始化
  76. beego.Run()
  77. }