diff --git a/cmd/icalm-benchmark/main.go b/cmd/icalm-benchmark/main.go index 3ddf10e..de45a7d 100644 --- a/cmd/icalm-benchmark/main.go +++ b/cmd/icalm-benchmark/main.go @@ -13,6 +13,8 @@ import ( "time" ) +var version string = "v0.0.0-dev" + func stress(network string, addr string, stop int) (time.Duration, int, int) { conn, err := net.Dial(network, addr) @@ -56,6 +58,7 @@ func stress(network string, addr string, stop int) (time.Duration, int, int) { func main() { var pFlag = flag.Int("p", runtime.NumCPU()/2, "Count of parallel worker routines to send queries") var cFlag = flag.Int("c", 100000, "Amount of quries to do with each worker routine") + var versionFlag = flag.Bool("version", false, "Prints version and exists") flag.Usage = func() { fmt.Fprintf(os.Stderr, "Usage: %s [flags] [PROTO]:[ADDR]\n\nFlags:\n", os.Args[0]) @@ -64,6 +67,11 @@ func main() { flag.Parse() + if *versionFlag { + fmt.Println(version) + os.Exit(0) + } + if flag.NArg() != 1 { flag.Usage() os.Exit(1) diff --git a/cmd/icalm-server/main.go b/cmd/icalm-server/main.go index 2d1c32a..d8e4765 100644 --- a/cmd/icalm-server/main.go +++ b/cmd/icalm-server/main.go @@ -12,15 +12,37 @@ import ( "syscall" ) +var version string = "v0.0.0-dev" + + func main() { - fmt.Println("IP: CIDR annotation lookup microservice") + var httplistenFlag = flag.String("http-listen", "", "Address on which the server will listen for http requests. Example: 127.0.0.1:8226") var linelistenFlag = flag.String("line-listen", "", "Address on which the server will listen for line-protocol requests. Example: 127.0.0.1:4226") var lineunixFlag = flag.String("line-unix", "", "Path of a unix-socket on which icalm provides a line-protocol lookup service. Example: /var/run/icalm/sock") var cidrfileFlag = flag.String("networks", "./networks.csv", "Path to the file containing the CIDR to annotation mapping.") + var versionFlag = flag.Bool("version", false, "Prints version and exists") flag.Parse() + flag.Usage = func(){ + fmt.Fprintf(os.Stderr, "Usage: %v [flags]\n\nFlags:\n", os.Args[0]) + flag.PrintDefaults() + } + + if *versionFlag { + fmt.Println(version) + os.Exit(0) + } + + fmt.Printf("IP: CIDR annotation lookup microservice [%v]\n", version) + + if *httplistenFlag == "" && *linelistenFlag == "" && *lineunixFlag == "" { + fmt.Fprintln(os.Stderr,"Useless. Need to serve on at least one method. Specify -http-listen, -line-listen or -line-unix") + flag.Usage() + os.Exit(1) + } + toclose := make([]io.Closer, 0) lookuptable, err := config.LoadLookupTableFromFile(*cidrfileFlag) @@ -51,12 +73,6 @@ func main() { toclose = append(toclose, lineunixserver) } - if len(toclose) == 0 { - fmt.Println("Useless. Need to serve on at least one method. Specify -http-listen, -line-listen or -line-unix: ") - flag.PrintDefaults() - os.Exit(1) - } - sigChan := make(chan os.Signal, 1) signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM) <-sigChan