ColdVerify_server.go 1.5 KB

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