main.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package main
  2. import (
  3. _ "Cold_GoodsOrder/Nats"
  4. "Cold_GoodsOrder/conf"
  5. "Cold_GoodsOrder/routers"
  6. _ "Cold_GoodsOrder/routers"
  7. "fmt"
  8. "github.com/beego/beego/v2/adapter/orm"
  9. beego "github.com/beego/beego/v2/server/web"
  10. "github.com/beego/beego/v2/server/web/filter/cors"
  11. _ "github.com/go-sql-driver/mysql"
  12. "runtime"
  13. "strconv"
  14. )
  15. func init() {
  16. fmt.Println(runtime.GOOS)
  17. orm.RegisterDriver("mysql", orm.DRMySQL)
  18. //orm.RegisterDataBase("default", "mysql", "zdxq:7e5853d9178edfcc@tcp(47.108.133.234:3306)/zdxq?charset=utf8",100,200)
  19. orm.RegisterDataBase("default", "mysql",
  20. conf.MysqlServer_Username+":"+conf.MysqlServer_Password+"@tcp("+conf.MysqlServer_UrlPort+")/"+conf.MysqlServer_Database+"?charset=utf8mb4&loc=Local&parseTime=True",
  21. conf.MysqlServer_MaxIdleConnections, conf.MysqlServer_MaxOpenConnections)
  22. orm.RunSyncdb("default", false, true) // 创建本地数据库
  23. }
  24. func main() {
  25. HTTPPort, _ := beego.AppConfig.String("HTTPPort")
  26. HTTPPort_int, _ := strconv.Atoi(HTTPPort)
  27. beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
  28. // 允许访问所有源
  29. AllowAllOrigins: true,
  30. // 可选参数"GET", "POST", "PUT", "DELETE", "OPTIONS" (*为所有)
  31. AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
  32. // 指的是允许的Header的种类
  33. AllowHeaders: []string{"Origin", "Authorization", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type", "T_pid"},
  34. // 公开的HTTP标头列表
  35. ExposeHeaders: []string{"Content-Length", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type"},
  36. // 如果设置,则允许共享身份验证凭据,例如cookie
  37. AllowCredentials: true,
  38. })).InsertFilter("/*", beego.BeforeRouter, routers.RBACFilter)
  39. beego.BConfig.AppName = conf.AppName // 项目名
  40. beego.BConfig.ServerName = conf.AppName + conf.HTTPPort //server 名称
  41. beego.BConfig.RunMode = "dev" // 应用的运行模式
  42. beego.BConfig.Listen.HTTPPort = HTTPPort_int //监听端口 本地:8518 线上:8528
  43. beego.Run()
  44. }