package main import ( "github.com/gin-gonic/gin" "github.com/mhaya" mhayaCron "github.com/mhaya/components/cron" mhayaGin "github.com/mhaya/components/gin" mhayaMongo "github.com/mhaya/components/mongo" checkCenter "github.com/mhaya/game/game_cluster/internal/component/check_center" "github.com/mhaya/game/game_cluster/internal/data" "github.com/mhaya/game/game_cluster/internal/mdb" "github.com/mhaya/game/game_cluster/nodes/web/controller" "github.com/mhaya/game/game_cluster/nodes/web/sdk" ) func main() { // 配置mhaya引擎,加载profile配置文件 app := mhaya.Configure("./game/config/profile-gc.json", "m-web-1", false, mhaya.Cluster) // 注册调度组件 app.Register(mhayaCron.New()) // 注册检查中心服是否启动组件 app.Register(checkCenter.New()) // 注册数据配表组件 app.Register(data.New()) // 加载http server组件 app.Register(httpServerComponent(app.Address())) // 注册db组件 app.Register(mhayaMongo.NewComponent()) app.AddActors( &mdb.ActorDB{}, ) // 加载sdk逻辑 sdk.Init(app) // 启动mhaya引擎 app.Startup() } func httpServerComponent(addr string) *mhayaGin.Component { gin.SetMode(gin.DebugMode) // new http server httpServer := mhayaGin.NewHttp("http_server", addr) httpServer.Use(mhayaGin.Cors()) // http server使用gin组件搭建,这里增加一个RecoveryWithZap中间件 httpServer.Use(mhayaGin.RecoveryWithZap(true)) //注册 controller httpServer.Register(new(controller.Controller)) return httpServer }