ColdVerify_local.go 3.3 KB

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