github.com/codingfuture/orig-energi3@v0.8.4/cmd/swarm/global-store/main.go (about)

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