Skip to content

Commit

Permalink
cli: add host and port flags
Browse files Browse the repository at this point in the history
  • Loading branch information
z7zmey committed Oct 15, 2017
1 parent 17fe6d6 commit 5a10960
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
5 changes: 4 additions & 1 deletion apiServer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@
package main

import (
"fmt"
"log"
"net/http"
)

// ListenAndServeAPI TODO
func ListenAndServeAPI() {
router := NewRouter()
err := http.ListenAndServe("0.0.0.0:8080", router)

serverHost := fmt.Sprintf("%s:%d", Config.host, Config.port)
err := http.ListenAndServe(serverHost, router)
log.Fatal(err)
}
10 changes: 9 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,27 @@ type CGConfig struct {
path ArrayFlags
exclude ArrayFlags
debug bool
host string
port int
}

var Config = CGConfig{}

func ParseConfigFlags() {
flag.Var(&Config.path, "path", "path to sources")
flag.Var(&Config.path, "p", "path to sources (shorthand)")
flag.Var(&Config.path, "P", "path to sources (shorthand)")

flag.Var(&Config.exclude, "exclude", "exclude path")
flag.Var(&Config.exclude, "e", "exclude path (shorthand)")

flag.BoolVar(&Config.debug, "debug", false, "print debug info")
flag.BoolVar(&Config.debug, "d", false, "print debug info (shorthand)")

flag.StringVar(&Config.host, "host", "127.0.0.1", "host")
flag.StringVar(&Config.host, "h", "127.0.0.1", "host (shorthand)")

flag.IntVar(&Config.port, "port", 8080, "port")
flag.IntVar(&Config.port, "p", 8080, "port (shorthand)")

flag.Parse()
}
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ func main() {
ProcessPath()

<-sigs
fmt.Println()
fmt.Println("test")
fmt.Println("exiting")
}

0 comments on commit 5a10960

Please sign in to comment.