1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- package main
- import (
- "ColdP_server/conf"
- _ "ColdP_server/routers"
- "fmt"
- "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/beego/beego/v2/server/web/filter/cors"
- _ "github.com/go-sql-driver/mysql"
- "runtime"
- "strconv"
- )
- func init() {
- fmt.Println(runtime.GOOS)
- orm.RegisterDriver("mysql", orm.DRMySQL)
- //orm.RegisterDataBase("default", "mysql", "zdxq:7e5853d9178edfcc@tcp(47.108.133.234:3306)/zdxq?charset=utf8",100,200)
- 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, false) // 创建数据库
- orm.Debug = true
- orm2.Debug = true
- }
- func main() {
- HTTPPort, _ := beego.AppConfig.String("HTTPPort")
- HTTPPort_int, _ := strconv.Atoi(HTTPPort)
- beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
- AllowAllOrigins: true,
- AllowMethods: []string{"*"},
- AllowHeaders: []string{"Origin", "Authorization", "Access-Control-Allow-Origin"},
- ExposeHeaders: []string{"Content-Length", "Access-Control-Allow-Origin"},
- AllowCredentials: true,
- }))
- beego.SetStaticPath("/ofile", "./ofile")
- beego.BConfig.AppName = "main_cold" // 项目名
- beego.BConfig.ServerName = "main_cold" //server 名称
- beego.BConfig.RunMode = "dev" // 应用的运行模式
- beego.BConfig.Listen.HTTPPort = HTTPPort_int //监听端口 本地:8518 线上:8528
- /* beego.AddFuncMap("convertm", convertM)
- */
- //go MqttServer.Run_MqttServer()
- beego.Run()
- }
|