diff options
| author | Jacob McDonnell <jacob@jacobmcdonnell.com> | 2025-06-14 15:00:13 -0400 |
|---|---|---|
| committer | Jacob McDonnell <jacob@jacobmcdonnell.com> | 2025-06-14 15:00:13 -0400 |
| commit | a66fea2e3aad4041563dff319c4e559d9e6a8194 (patch) | |
| tree | f51dadc73bde8ad622acfce7a312ed39bd682478 | |
| parent | e55fbab6a1e1b482e2d928555c7e17ff9a2ecc79 (diff) | |
Port selection option
| -rw-r--r-- | main.go | 23 |
1 files changed, 22 insertions, 1 deletions
@@ -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)) } |
