web.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. mhayaMongo "github.com/mhaya/components/mongo"
  8. checkCenter "github.com/mhaya/game/game_cluster/internal/component/check_center"
  9. "github.com/mhaya/game/game_cluster/internal/data"
  10. "github.com/mhaya/game/game_cluster/internal/mdb"
  11. mdb2 "github.com/mhaya/game/game_cluster/nodes/webadmin/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.AddActors(
  28. &mdb.ActorDB{},
  29. )
  30. mdb2.InitializeMongoDB()
  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. }