main.go 3.8 KB

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