diff --git a/main.go b/main.go index 529cf85..6428348 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "encoding/csv" "encoding/json" + "flag" "fmt" "log" "net/http" @@ -91,6 +92,9 @@ func TradesHandler(w http.ResponseWriter, r *http.Request) { // ---------- Main ---------- func main() { + port := flag.String("port", "8081", "port to listen on") + flag.Parse() + http.HandleFunc("/styles.css", Styles) http.HandleFunc("/", Home) http.HandleFunc("/about", About) @@ -102,8 +106,8 @@ func main() { http.HandleFunc("/trades", TradesHandler) http.HandleFunc("/api/prices", PricesHandler) - fmt.Println("running on http://localhost:8081/") - if err := http.ListenAndServe(":8081", nil); err != nil { + fmt.Printf("running on http://localhost:%s/\n", *port) + if err := http.ListenAndServe(":"+*port, nil); err != nil { log.Fatal(err) } }