package main import ( "fmt" mhayaConst "github.com/mhaya/const" "github.com/mhaya/game/game_cluster/nodes/adminapi" "github.com/mhaya/game/game_cluster/nodes/center/center" "github.com/mhaya/game/game_cluster/nodes/game/game" "github.com/mhaya/game/game_cluster/nodes/webadmin" // "github.com/mhaya/game/game_cluster/nodes/gate" "github.com/mhaya/game/game_cluster/nodes/master/master" "github.com/mhaya/game/game_cluster/nodes/web/web" "github.com/urfave/cli/v2" "os" ) func main() { app := &cli.App{ Name: "game cluster node", Description: "game cluster node game", Commands: []*cli.Command{ versionCommand(), masterCommand(), centerCommand(), webCommand(), //gateCommand(), gameCommand(), webadminCommand(), adminApiCommand(), }, } _ = app.Run(os.Args) } func versionCommand() *cli.Command { return &cli.Command{ Name: "version", Aliases: []string{"ver", "v"}, Usage: "view version", UsageText: "game cluster node version", Action: func(c *cli.Context) error { fmt.Println(mhayaConst.Version()) return nil }, } } func masterCommand() *cli.Command { return &cli.Command{ Name: "master", Usage: "run master node", UsageText: "node master --path=./game/config/profile-gc.json --node=m-master", Flags: getFlag(), Action: func(c *cli.Context) error { path, node := getParameters(c) master.Run(path, node) return nil }, } } func centerCommand() *cli.Command { return &cli.Command{ Name: "center", Usage: "run center node", UsageText: "node center --path=./game/config/profile-gc.json --node=m-center", Flags: getFlag(), Action: func(c *cli.Context) error { path, node := getParameters(c) center.Run(path, node) return nil }, } } func webCommand() *cli.Command { return &cli.Command{ Name: "web", Usage: "run web node", UsageText: "node web --path=./game/config/profile-gc.json --node=m-web-1", Flags: getFlag(), Action: func(c *cli.Context) error { path, node := getParameters(c) web.Run(path, node) return nil }, } } func webadminCommand() *cli.Command { return &cli.Command{ Name: "webadmin", Usage: "run webadmin node", UsageText: "node webadmin --path=./game/config/profile-gc.json --node=m-webadmin-1", Flags: getFlag(), Action: func(c *cli.Context) error { path, node := getParameters(c) webadmin.Run(path, node) return nil }, } } func adminApiCommand() *cli.Command { return &cli.Command{ Name: "adminapi", Usage: "run adminapi node", UsageText: "node adminapi --path=./game/config/profile-gc.json --node=m-web-admin-api-1", Flags: getFlag(), Action: func(c *cli.Context) error { path, node := getParameters(c) adminapi.Run(path, node) return nil }, } } /*func gateCommand() *cli.Command { return &cli.Command{ Name: "gate", Usage: "run gate node", UsageText: "node gate --path=./game/config/profile-gc.json --node=m-gate-1", Flags: getFlag(), Action: func(c *cli.Context) error { path, node := getParameters(c) gate.Run(path, node) return nil }, } }*/ func gameCommand() *cli.Command { return &cli.Command{ Name: "game", Usage: "run game node", UsageText: "node game --path=./game/config/profile-gc.json --node=10001", Flags: getFlag(), Action: func(c *cli.Context) error { path, node := getParameters(c) game.Run(path, node) return nil }, } } func getParameters(c *cli.Context) (path, node string) { path = c.String("path") node = c.String("node") return path, node } func getFlag() []cli.Flag { return []cli.Flag{ &cli.StringFlag{ Name: "path", Usage: "profile config path", Required: false, Value: "./game/config/profile-gc.json", }, &cli.StringFlag{ Name: "node", Usage: "node id name", Required: true, Value: "", }, } }