main.go 1.9 KB

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