From 5bbc9b922c66874a3764e7c462ca2d173316d9d7 Mon Sep 17 00:00:00 2001 From: cynic Date: Thu, 13 Jun 2024 21:02:13 +0000 Subject: [PATCH] add port argument --- whoami.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/whoami.go b/whoami.go index b3a00ad..189d1c6 100644 --- a/whoami.go +++ b/whoami.go @@ -5,6 +5,7 @@ import ( "net" "strings" "encoding/base32" + "os" ) // DomainFromIP derives a meshname subdomain for the authoritative DNS server address @@ -27,6 +28,13 @@ func handler(w http.ResponseWriter, r *http.Request) { func main() { http.HandleFunc("/", handler) - http.ListenAndServe(":3000", nil) + listenPort := "3000" + // Get the first command-line argument + if len(os.Args) > 1 { + listenPort = os.Args[1] + } + print("Listening on port:", listenPort, "\n") + listenPort = strings.Join([]string{":", listenPort}, "") + http.ListenAndServe(listenPort, nil) }