Skip to content

Commit

Permalink
Print version information
Browse files Browse the repository at this point in the history
  • Loading branch information
securitym0nkey committed May 22, 2024
1 parent 1d18d09 commit 08d8c63
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
8 changes: 8 additions & 0 deletions cmd/icalm-benchmark/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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])
Expand All @@ -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)
Expand Down
30 changes: 23 additions & 7 deletions cmd/icalm-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 08d8c63

Please sign in to comment.