diff options
author | Emile <hanemile@protonmail.com> | 2019-08-30 00:17:40 +0200 |
---|---|---|
committer | Emile <hanemile@protonmail.com> | 2019-08-30 00:17:40 +0200 |
commit | db852c81422a01c9ee09ae549aa5701ccd92165a (patch) | |
tree | 185103839553e8a96c22b95adcc3cd78d504fde5 | |
parent | d4471645a0749bc46aee62b83621bbede0bd2538 (diff) |
added a command line flag for specifing on which port the server should listen
-rw-r--r-- | server.go | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/server.go b/server.go index 5524b0a..626a542 100644 --- a/server.go +++ b/server.go @@ -2,6 +2,7 @@ package main import ( "encoding/json" + "flag" "fmt" "io/ioutil" "log" @@ -16,16 +17,23 @@ import ( var ( categories []string + port int ) func main() { + initFlags() r := mux.NewRouter() r.HandleFunc("/", indexHandler) r.HandleFunc("/dumpall", dumpallHandler) r.HandleFunc("/{station}/{name}", getHandler) - log.Fatal(http.ListenAndServe(":8080", r)) + log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", port), r)) +} + +func initFlags() { + flag.IntVar(&port, "p", 8080, "the port the server should listen on") + flag.Parse() } func indexHandler(w http.ResponseWriter, r *http.Request) { |