package main import ( "Yunlot/Nats" _ "Yunlot/Nats" "Yunlot/Plugin" "Yunlot/RunCode" "Yunlot/TimeTask" "Yunlot/conf" "Yunlot/logs" _ "Yunlot/routers" "github.com/beego/beego/v2/adapter/orm" orm2 "github.com/beego/beego/v2/client/orm" beego "github.com/beego/beego/v2/server/web" _ "github.com/go-sql-driver/mysql" "strconv" ) func init() { logs.Println("MysqlServer:" + conf.MysqlServer_Username + ":" + conf.MysqlServer_Password + "@tcp(" + conf.MysqlServer_UrlPort + ")/" + conf.MysqlServer_Database + "?charset=utf8mb4&loc=Local&parseTime=True") 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) // 创建数据库 } 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 orm2.Debug = true logs.Println("MqttServer", " ======= 项目启动 ========") //go MqttServer2.Run_MqttServer() // MQTT 通讯 //go MqttServer.MqttPolling() // MQTT 设备轮询 //go MqttServer.DeviceMqttMap_go() //// 缓存数据发送-确保设备在休眠后 能收到数据 // MQTT 通讯 //if conf.MqttServer_Open == 1 { // mode := Product.ProductMode{ // Id: 1, // T_name: "MQTT", // T_address: fmt.Sprintf("mqtt://%s", conf.MqttServer_Url), // T_describe: "MQTT 接入方式为设备和云平台提供双向连接,设备既可上报属性数据,也可接收云端的消息下发。", // T_state: 1, // } // Product.ProductModeAdd(mode) // go MqttServer.Run_MqttServer() //} //// TCP 通讯 //if conf.TCPServer_Open == 1 { // mode := Product.ProductMode{ // Id: 2, // T_name: "TCP", // T_address: fmt.Sprintf("TCP:%d", conf.TCPServer_Port), // T_describe: "TCP 接入方式为设备和云平台提供双向连接,设备既可上报属性数据,也可接收云端的消息下发。", // T_state: 1, // } // Product.ProductModeAdd(mode) // go TcpServer.TcpServer() //} //// HTTP 通讯 //if conf.HTTPServer_Open == 1 { // mode := Product.ProductMode{ // Id: 6, // T_name: "HTTP", // T_address: fmt.Sprintf("http://:%d", conf.HTTPServer_Port), // T_describe: "HTTP 接入方式为设备和云平台提供双向连接,设备既可上报属性数据,也可接收云端的消息下发。", // T_state: 1, // } // Product.ProductModeAdd(mode) // go HttpServer.Run() //} //go Nats.NatsInit() // Nats 通讯 go TimeTask.Init() // 时间任务 go RunCode.RunCode_Inte() // 代码编译 go Nats.Nats_Server_init() // 内部 Nats 通讯 go Plugin.PluginInit() // Plugin 初始化 beego.Run() }