package main import ( "Cold_mqtt/MqttServer" "Cold_mqtt/Nats" "Cold_mqtt/Plugins" "Cold_mqtt/TimeTask" "Cold_mqtt/conf" "Cold_mqtt/logs" _ "Cold_mqtt/routers" "github.com/beego/beego/v2/adapter/orm" beego "github.com/beego/beego/v2/server/web" _ "github.com/go-sql-driver/mysql" "strconv" ) func init() { println("--------------- go --------------") orm.RegisterDriver("mysql", orm.DRMySQL) orm.RegisterDataBase("default", "mysql", conf.MysqlServer_Username+":"+conf.MysqlServer_Password+"@tcp("+conf.MysqlServer_UrlPort+")/"+conf.MysqlServer_Database+"?charset=utf8mb4&loc=Local&parseTime=True", conf.MysqlServer_MaxIdleConnections, conf.MysqlServer_MaxOpenConnections) orm.RunSyncdb("default", false, true) // 创建数据库 //logs.Println("MysqlServer:" + conf.MysqlServer_Username + ":" + conf.MysqlServer_Password + "@tcp(" + conf.MysqlServer_UrlPort + ")/" + conf.MysqlServer_Database + "?charset=utf8mb4&loc=Local&parseTime=True") } func main() { beego.BConfig.AppName = conf.AppName + "_" + strconv.Itoa(conf.HTTPPort) // 项目名 beego.BConfig.ServerName = conf.AppName + "_" + strconv.Itoa(conf.HTTPPort) //server 名称 beego.BConfig.RunMode = "dev" // 应用的运行模式 beego.BConfig.Listen.HTTPPort = conf.HTTPPort //监听端口 本地:8518 线上:8528 logs.Println("MqttServer", " ======= 项目启动 ========") go MqttServer.Run_MqttServer() // MQTT 通讯 ////go MqttServer.MqttPolling() // MQTT 设备轮询 go MqttServer.DeviceMqttMap_go() //// 缓存数据发送-确保设备在休眠后 能收到数据 go Nats.NatsInit() // Nats 通讯 go TimeTask.Init() // 时间任务 go Plugins.ContinuousPushOfOfflineDeviceWarning() //设备离线报警连续推送 beego.Run() }