main.go 1.51 KB
Newer Older
Richer Maximilien's avatar
Richer Maximilien committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
package main

import (
	"dfss"
	dapi "dfss/dfssd/api"
	"flag"
	"fmt"
	"runtime"
)

var (
	verbose, demo        bool
	port, address, dbURI string
)

func init() {

	flag.BoolVar(&verbose, "v", false, "Print verbose messages")
	flag.BoolVar(&demo, "d", false, "Enable demonstrator")

	flag.StringVar(&port, "p", "9010", "Default port listening")
	flag.StringVar(&address, "a", "0.0.0.0", "Default address to bind for listening")

	flag.StringVar(&dbURI, "db", "mongodb://localhost/dfss", "Name of the environment variable containing the server url in standard MongoDB format")

	flag.Usage = func() {
		fmt.Println("DFSS TTP v" + dfss.Version)
		fmt.Println("Trusted third party resolver")

		fmt.Println("\nUsage:")
		fmt.Println("  dfssp [flags] command")

		fmt.Println("\nThe commands are:")
		fmt.Println("  start    [db, a, p]")
		fmt.Println("           start the TTP service")
		fmt.Println("  help     print this help")
		fmt.Println("  version  print dfss protocol version")

		fmt.Println("\nFlags:")
		flag.PrintDefaults()

		fmt.Println()
	}
}

func main() {
	flag.Parse()
	command := flag.Arg(0)
	dapi.Switch(demo)

	switch command {
	case "version":
		fmt.Println("v"+dfss.Version, runtime.GOOS, runtime.GOARCH)
	case "start":
		// srv := server.GetServer(dbURI, verbose)
		// fmt.Println("Listening on " + address + ":" + port)
		// dapi.DLog("TTP server started on " + address + ":" + port)
		// err := net.Listen(address+":"+port, srv)
		// if err != nil {
		//	  fmt.Println(err)
		// }
	default:
		flag.Usage()
	}

	dapi.DClose()
}