web.go 1.4 KB

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