Cold_server.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package main
  2. import (
  3. "ColdP_server/conf"
  4. _ "ColdP_server/routers"
  5. "fmt"
  6. "github.com/beego/beego/v2/adapter/orm"
  7. orm2 "github.com/beego/beego/v2/client/orm"
  8. beego "github.com/beego/beego/v2/server/web"
  9. "github.com/beego/beego/v2/server/web/filter/cors"
  10. _ "github.com/go-sql-driver/mysql"
  11. "runtime"
  12. "strconv"
  13. )
  14. func init() {
  15. fmt.Println(runtime.GOOS)
  16. orm.RegisterDriver("mysql", orm.DRMySQL)
  17. //orm.RegisterDataBase("default", "mysql", "zdxq:7e5853d9178edfcc@tcp(47.108.133.234:3306)/zdxq?charset=utf8",100,200)
  18. orm.RegisterDataBase("default", "mysql",
  19. conf.MysqlServer_Username+":"+conf.MysqlServer_Password+"@tcp("+conf.MysqlServer_UrlPort+")/"+conf.MysqlServer_Database+"?charset=utf8mb4&loc=Local&parseTime=True",
  20. conf.MysqlServer_MaxIdleConnections, conf.MysqlServer_MaxOpenConnections)
  21. orm.RunSyncdb("default", false, false) // 创建数据库
  22. orm.Debug = true
  23. orm2.Debug = true
  24. }
  25. func main() {
  26. HTTPPort, _ := beego.AppConfig.String("HTTPPort")
  27. HTTPPort_int, _ := strconv.Atoi(HTTPPort)
  28. beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
  29. AllowAllOrigins: true,
  30. AllowMethods: []string{"*"},
  31. AllowHeaders: []string{"Origin", "Authorization", "Access-Control-Allow-Origin"},
  32. ExposeHeaders: []string{"Content-Length", "Access-Control-Allow-Origin"},
  33. AllowCredentials: true,
  34. }))
  35. beego.SetStaticPath("/ofile", "./ofile")
  36. beego.BConfig.AppName = "main_cold" // 项目名
  37. beego.BConfig.ServerName = "main_cold" //server 名称
  38. beego.BConfig.RunMode = "dev" // 应用的运行模式
  39. beego.BConfig.Listen.HTTPPort = HTTPPort_int //监听端口 本地:8518 线上:8528
  40. /* beego.AddFuncMap("convertm", convertM)
  41. */
  42. //go MqttServer.Run_MqttServer()
  43. beego.Run()
  44. }