web.go 1.2 KB

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