github.com/daeglee/go-ethereum@v0.0.0-20190504220456-cad3e8d18e9b/cmd/swarm/global-store/main.go (about) 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 17 package main 18 19 import ( 20 "os" 21 22 "github.com/ethereum/go-ethereum/log" 23 cli "gopkg.in/urfave/cli.v1" 24 ) 25 26 var ( 27 version = "0.1" 28 gitCommit string // Git SHA1 commit hash of the release (set via linker flags) 29 ) 30 31 func main() { 32 err := newApp().Run(os.Args) 33 if err != nil { 34 log.Error(err.Error()) 35 os.Exit(1) 36 } 37 } 38 39 // newApp construct a new instance of Swarm Global Store. 40 // Method Run is called on it in the main function and in tests. 41 func newApp() (app *cli.App) { 42 app = cli.NewApp() 43 app.Name = "global-store" 44 app.Version = version 45 if len(gitCommit) >= 8 { 46 app.Version += "-" + gitCommit[:8] 47 } 48 app.Usage = "Swarm Global Store" 49 50 // app flags (for all commands) 51 app.Flags = []cli.Flag{ 52 cli.IntFlag{ 53 Name: "verbosity", 54 Value: 3, 55 Usage: "Verbosity level.", 56 }, 57 cli.StringFlag{ 58 Name: "explorer-address", 59 Value: "", 60 Usage: "Chunk explorer HTTP listener address.", 61 }, 62 cli.StringSliceFlag{ 63 Name: "explorer-cors-origin", 64 Value: nil, 65 Usage: "Chunk explorer CORS origin (can be specified multiple times).", 66 }, 67 } 68 69 app.Commands = []cli.Command{ 70 { 71 Name: "http", 72 Aliases: []string{"h"}, 73 Usage: "Start swarm global store with HTTP server.", 74 Action: startHTTP, 75 // Flags only for "start" command. 76 // Allow app flags to be specified after the 77 // command argument. 78 Flags: append(app.Flags, 79 cli.StringFlag{ 80 Name: "dir", 81 Value: "", 82 Usage: "Data directory.", 83 }, 84 cli.StringFlag{ 85 Name: "addr", 86 Value: "0.0.0.0:3033", 87 Usage: "Address to listen for HTTP connections.", 88 }, 89 ), 90 }, 91 { 92 Name: "websocket", 93 Aliases: []string{"ws"}, 94 Usage: "Start swarm global store with WebSocket server.", 95 Action: startWS, 96 // Flags only for "start" command. 97 // Allow app flags to be specified after the 98 // command argument. 99 Flags: append(app.Flags, 100 cli.StringFlag{ 101 Name: "dir", 102 Value: "", 103 Usage: "Data directory.", 104 }, 105 cli.StringFlag{ 106 Name: "addr", 107 Value: "0.0.0.0:3033", 108 Usage: "Address to listen for WebSocket connections.", 109 }, 110 cli.StringSliceFlag{ 111 Name: "origin", 112 Value: nil, 113 Usage: "WebSocket CORS origin (can be specified multiple times).", 114 }, 115 ), 116 }, 117 } 118 119 return app 120 }