main.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // Copyright 2019 The go-ethereum Authors
  2. // This file is part of go-ethereum.
  3. //
  4. // go-ethereum is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // go-ethereum is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
  16. package main
  17. import (
  18. "os"
  19. "github.com/ethereum/go-ethereum/log"
  20. cli "gopkg.in/urfave/cli.v1"
  21. )
  22. var (
  23. version = "0.1"
  24. gitCommit string // Git SHA1 commit hash of the release (set via linker flags)
  25. gitDate string
  26. )
  27. func main() {
  28. err := newApp().Run(os.Args)
  29. if err != nil {
  30. log.Error(err.Error())
  31. os.Exit(1)
  32. }
  33. }
  34. // newApp construct a new instance of Swarm Global Store.
  35. // Method Run is called on it in the main function and in tests.
  36. func newApp() (app *cli.App) {
  37. app = cli.NewApp()
  38. app.Name = "global-store"
  39. app.Version = version
  40. if len(gitCommit) >= 8 {
  41. app.Version += "-" + gitCommit[:8]
  42. }
  43. if gitDate != "" {
  44. app.Version += "-" + gitDate
  45. }
  46. app.Usage = "Swarm Global Store"
  47. // app flags (for all commands)
  48. app.Flags = []cli.Flag{
  49. cli.IntFlag{
  50. Name: "verbosity",
  51. Value: 3,
  52. Usage: "Verbosity level.",
  53. },
  54. cli.StringFlag{
  55. Name: "explorer-address",
  56. Value: "",
  57. Usage: "Chunk explorer HTTP listener address.",
  58. },
  59. cli.StringSliceFlag{
  60. Name: "explorer-cors-origin",
  61. Value: nil,
  62. Usage: "Chunk explorer CORS origin (can be specified multiple times).",
  63. },
  64. }
  65. app.Commands = []cli.Command{
  66. {
  67. Name: "http",
  68. Aliases: []string{"h"},
  69. Usage: "Start swarm global store with HTTP server.",
  70. Action: startHTTP,
  71. // Flags only for "start" command.
  72. // Allow app flags to be specified after the
  73. // command argument.
  74. Flags: append(app.Flags,
  75. cli.StringFlag{
  76. Name: "dir",
  77. Value: "",
  78. Usage: "Data directory.",
  79. },
  80. cli.StringFlag{
  81. Name: "addr",
  82. Value: "0.0.0.0:3033",
  83. Usage: "Address to listen for HTTP connections.",
  84. },
  85. ),
  86. },
  87. {
  88. Name: "websocket",
  89. Aliases: []string{"ws"},
  90. Usage: "Start swarm global store with WebSocket server.",
  91. Action: startWS,
  92. // Flags only for "start" command.
  93. // Allow app flags to be specified after the
  94. // command argument.
  95. Flags: append(app.Flags,
  96. cli.StringFlag{
  97. Name: "dir",
  98. Value: "",
  99. Usage: "Data directory.",
  100. },
  101. cli.StringFlag{
  102. Name: "addr",
  103. Value: "0.0.0.0:3033",
  104. Usage: "Address to listen for WebSocket connections.",
  105. },
  106. cli.StringSliceFlag{
  107. Name: "origin",
  108. Value: nil,
  109. Usage: "WebSocket CORS origin (can be specified multiple times).",
  110. },
  111. ),
  112. },
  113. }
  114. return app
  115. }