port option

This commit is contained in:
samantha42
2026-03-16 15:13:36 +01:00
parent 9ed735c133
commit a4e38e2f86
+6 -2
View File
@@ -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)
}
}