main.go 4.3 KB

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