ColdVerify_server.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package main
  2. import (
  3. "ColdVerify_server/conf"
  4. _ "ColdVerify_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, true) // 创建数据库
  22. orm2.Debug = 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"},
  34. // 公开的HTTP标头列表
  35. ExposeHeaders: []string{"Content-Length", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type"},
  36. // 如果设置,则允许共享身份验证凭据,例如cookie
  37. AllowCredentials: true,
  38. }))
  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. }