From a66fea2e3aad4041563dff319c4e559d9e6a8194 Mon Sep 17 00:00:00 2001 From: Jacob McDonnell Date: Sat, 14 Jun 2025 15:00:13 -0400 Subject: Port selection option --- main.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'main.go') diff --git a/main.go b/main.go index 20deaff..7fd73d2 100644 --- a/main.go +++ b/main.go @@ -91,12 +91,33 @@ func ErrorPage(w http.ResponseWriter, message string, code int) { }) } +func Usage() { + fmt.Fprintf(os.Stderr, "%s [--port port]\n", os.Args[0]) +} + func main() { + port := ":8000" + + for i := 1; i < len(os.Args); i++ { + switch os.Args[i] { + case "--port": + if i+1 >= len(os.Args) { + Usage() + } else { + port = ":" + os.Args[i+1] + i++ + } + default: + log.Println("Unknown option: ", os.Args[i]) + Usage() + } + } + http.HandleFunc("/robots.txt", GetFiles) http.HandleFunc("/rss.xml", GetFiles) http.HandleFunc("/card", GetFiles) http.HandleFunc("/css/", GetFiles) http.HandleFunc("/logos/", GetFiles) http.HandleFunc("/", GetHome) - log.Fatal(http.ListenAndServe(":8000", nil)) + log.Fatal(http.ListenAndServe(port, nil)) } -- cgit v1.2.3