web.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package main
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "github.com/mhaya"
  5. mhayaCron "github.com/mhaya/components/cron"
  6. mhayaGin "github.com/mhaya/components/gin"
  7. mhayaGORM "github.com/mhaya/components/gorm"
  8. mhayaMongo "github.com/mhaya/components/mongo"
  9. checkCenter "github.com/mhaya/game/game_cluster/internal/component/check_center"
  10. "github.com/mhaya/game/game_cluster/internal/data"
  11. "github.com/mhaya/game/game_cluster/internal/mdb"
  12. mdb2 "github.com/mhaya/game/game_cluster/nodes/webadmin/mdb"
  13. "github.com/mhaya/game/game_cluster/nodes/webadmin/router"
  14. )
  15. func main() {
  16. // 配置mhaya引擎,加载profile配置文件
  17. app := mhaya.Configure("./game/config/profile-gc.json", "m-web-admin-1", false, mhaya.Cluster)
  18. // 注册调度组件
  19. app.Register(mhayaCron.New())
  20. // 注册检查中心服是否启动组件
  21. app.Register(checkCenter.New())
  22. // 注册数据配表组件
  23. app.Register(data.New())
  24. // 加载http server组件
  25. app.Register(httpServerComponent(app.Address()))
  26. // 注册db组件
  27. app.Register(mhayaMongo.NewComponent())
  28. app.Register(mhayaGORM.NewComponent())
  29. app.AddActors(
  30. &mdb.ActorDB{},
  31. )
  32. mdb2.InitializeMongoDB()
  33. // 启动mhaya引擎
  34. app.Startup()
  35. }
  36. func httpServerComponent(addr string) *mhayaGin.Component {
  37. gin.SetMode(gin.DebugMode)
  38. // new http server
  39. httpServer := mhayaGin.NewHttp("http_server", addr)
  40. httpServer.Use(mhayaGin.Cors())
  41. // http server使用gin组件搭建,这里增加一个RecoveryWithZap中间件
  42. httpServer.Use(mhayaGin.RecoveryWithZap(true))
  43. // 注册 controller
  44. httpServer.Register(new(router.Controller))
  45. return httpServer
  46. }