web.go 1.5 KB

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