github.com/tenywen/fabric@v1.0.0-beta.0.20170620030522-a5b1ed380643/common/tools/configtxlator/main.go (about) 1 /* 2 Copyright IBM Corp. 2017 All Rights Reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package main 18 19 import ( 20 "fmt" 21 "net/http" 22 "os" 23 24 "github.com/hyperledger/fabric/common/tools/configtxlator/metadata" 25 "github.com/hyperledger/fabric/common/tools/configtxlator/rest" 26 "github.com/op/go-logging" 27 "gopkg.in/alecthomas/kingpin.v2" 28 ) 29 30 var logger = logging.MustGetLogger("configtxlator") 31 32 // command line flags 33 var ( 34 app = kingpin.New("configtxlator", "Utility for generating Hyperledger Fabric channel configurations") 35 36 start = app.Command("start", "Start the configtxlator REST server") 37 hostname = start.Flag("hostname", "The hostname or IP on which the REST server will listen").Default("0.0.0.0").String() 38 port = start.Flag("port", "The port on which the REST server will listen").Default("7059").Int() 39 40 version = app.Command("version", "Show version information") 41 ) 42 43 func main() { 44 kingpin.Version("0.0.1") 45 switch kingpin.MustParse(app.Parse(os.Args[1:])) { 46 // "start" command 47 case start.FullCommand(): 48 startServer(fmt.Sprintf("%s:%d", *hostname, *port)) 49 50 // "version" command 51 case version.FullCommand(): 52 printVersion() 53 } 54 55 } 56 57 func startServer(address string) { 58 logger.Infof("Serving HTTP requests on %s", address) 59 err := http.ListenAndServe(address, rest.NewRouter()) 60 61 app.Fatalf("Error starting server:[%s]\n", err) 62 } 63 64 func printVersion() { 65 fmt.Println(metadata.GetVersionInfo()) 66 }