summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--server.go10
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) {