main.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. package main
  2. import (
  3. "fmt"
  4. mhayaConst "github.com/mhaya/const"
  5. "github.com/mhaya/game/game_cluster/nodes/center/center"
  6. "github.com/mhaya/game/game_cluster/nodes/game/game"
  7. // "github.com/mhaya/game/game_cluster/nodes/gate"
  8. "github.com/mhaya/game/game_cluster/nodes/master/master"
  9. "github.com/mhaya/game/game_cluster/nodes/web/web"
  10. "github.com/urfave/cli/v2"
  11. "os"
  12. )
  13. func main() {
  14. app := &cli.App{
  15. Name: "game cluster node",
  16. Description: "game cluster node game",
  17. Commands: []*cli.Command{
  18. versionCommand(),
  19. masterCommand(),
  20. centerCommand(),
  21. webCommand(),
  22. //gateCommand(),
  23. gameCommand(),
  24. },
  25. }
  26. _ = app.Run(os.Args)
  27. }
  28. func versionCommand() *cli.Command {
  29. return &cli.Command{
  30. Name: "version",
  31. Aliases: []string{"ver", "v"},
  32. Usage: "view version",
  33. UsageText: "game cluster node version",
  34. Action: func(c *cli.Context) error {
  35. fmt.Println(mhayaConst.Version())
  36. return nil
  37. },
  38. }
  39. }
  40. func masterCommand() *cli.Command {
  41. return &cli.Command{
  42. Name: "master",
  43. Usage: "run master node",
  44. UsageText: "node master --path=./game/config/profile-gc.json --node=m-master",
  45. Flags: getFlag(),
  46. Action: func(c *cli.Context) error {
  47. path, node := getParameters(c)
  48. master.Run(path, node)
  49. return nil
  50. },
  51. }
  52. }
  53. func centerCommand() *cli.Command {
  54. return &cli.Command{
  55. Name: "center",
  56. Usage: "run center node",
  57. UsageText: "node center --path=./game/config/profile-gc.json --node=m-center",
  58. Flags: getFlag(),
  59. Action: func(c *cli.Context) error {
  60. path, node := getParameters(c)
  61. center.Run(path, node)
  62. return nil
  63. },
  64. }
  65. }
  66. func webCommand() *cli.Command {
  67. return &cli.Command{
  68. Name: "web",
  69. Usage: "run web node",
  70. UsageText: "node web --path=./game/config/profile-gc.json --node=m-web-1",
  71. Flags: getFlag(),
  72. Action: func(c *cli.Context) error {
  73. path, node := getParameters(c)
  74. web.Run(path, node)
  75. return nil
  76. },
  77. }
  78. }
  79. /*func gateCommand() *cli.Command {
  80. return &cli.Command{
  81. Name: "gate",
  82. Usage: "run gate node",
  83. UsageText: "node gate --path=./game/config/profile-gc.json --node=m-gate-1",
  84. Flags: getFlag(),
  85. Action: func(c *cli.Context) error {
  86. path, node := getParameters(c)
  87. gate.Run(path, node)
  88. return nil
  89. },
  90. }
  91. }*/
  92. func gameCommand() *cli.Command {
  93. return &cli.Command{
  94. Name: "game",
  95. Usage: "run game node",
  96. UsageText: "node game --path=./game/config/profile-gc.json --node=10001",
  97. Flags: getFlag(),
  98. Action: func(c *cli.Context) error {
  99. path, node := getParameters(c)
  100. game.Run(path, node)
  101. return nil
  102. },
  103. }
  104. }
  105. func getParameters(c *cli.Context) (path, node string) {
  106. path = c.String("path")
  107. node = c.String("node")
  108. return path, node
  109. }
  110. func getFlag() []cli.Flag {
  111. return []cli.Flag{
  112. &cli.StringFlag{
  113. Name: "path",
  114. Usage: "profile config path",
  115. Required: false,
  116. Value: "./game/config/profile-gc.json",
  117. },
  118. &cli.StringFlag{
  119. Name: "node",
  120. Usage: "node id name",
  121. Required: true,
  122. Value: "",
  123. },
  124. }
  125. }