main.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package main
  2. import (
  3. "Cold_WorkOrder/Nats"
  4. "Cold_WorkOrder/conf"
  5. "Cold_WorkOrder/routers"
  6. _ "Cold_WorkOrder/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. Nats.Init()
  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. // 允许访问所有源
  30. AllowAllOrigins: true,
  31. // 可选参数"GET", "POST", "PUT", "DELETE", "OPTIONS" (*为所有)
  32. AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
  33. // 指的是允许的Header的种类
  34. AllowHeaders: []string{"Origin", "Authorization", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type", "T_pid"},
  35. // 公开的HTTP标头列表
  36. ExposeHeaders: []string{"Content-Length", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type"},
  37. // 如果设置,则允许共享身份验证凭据,例如cookie
  38. AllowCredentials: true,
  39. })).InsertFilter("/*", beego.BeforeRouter, routers.FilterRBAC)
  40. beego.BConfig.AppName = conf.AppName // 项目名
  41. beego.BConfig.ServerName = conf.AppName + conf.HTTPPort //server 名称
  42. beego.BConfig.RunMode = "dev" // 应用的运行模式
  43. beego.BConfig.Listen.HTTPPort = HTTPPort_int //监听端口 本地:8518 线上:8528
  44. beego.Run()
  45. }