summaryrefslogtreecommitdiffstats
path: root/main.go
diff options
context:
space:
mode:
authorsiddharth <s@ricketyspace.net>2022-05-22 18:19:50 -0400
committersiddharth <s@ricketyspace.net>2022-05-22 18:19:50 -0400
commit6f7883f96cd80da47f38c00b3470e0e00adae4a5 (patch)
tree8507182c48b5f2ede6b0c5f920ee59bb66f1ea7a /main.go
parent12a49ac3a4236fe61ebe3651625c273f48fed81b (diff)
main: allow listening on custom port
Diffstat (limited to 'main.go')
-rw-r--r--main.go17
1 files changed, 16 insertions, 1 deletions
diff --git a/main.go b/main.go
index 2f4448e..e6e455b 100644
--- a/main.go
+++ b/main.go
@@ -5,6 +5,7 @@ package main
import (
"embed"
+ "flag"
"fmt"
"html/template"
"log"
@@ -14,6 +15,12 @@ import (
"ricketyspace.net/peach/nws"
)
+// Peach port. Defaults to 8151
+var peachPort = flag.Int("p", 8151, "Port to run peach on")
+
+// Peach listen address. Set during init.
+var peachAddr = ""
+
// Holds static content.
//go:embed html static
var peachFS embed.FS
@@ -47,6 +54,14 @@ type WeatherTimeline struct {
Periods []WeatherPeriod
}
+func init() {
+ flag.Parse()
+ if *peachPort < 80 {
+ log.Fatalf("port number is invalid: %v", *peachPort)
+ }
+ peachAddr = fmt.Sprintf(":%d", *peachPort)
+}
+
func main() {
http.Handle("/static/", http.FileServer(http.FS(peachFS)))
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
@@ -56,7 +71,7 @@ func main() {
}
showWeather(w, 41.115, -83.177)
})
- log.Fatal(http.ListenAndServe(":8151", nil))
+ log.Fatal(http.ListenAndServe(peachAddr, nil))
}
func showWeather(w http.ResponseWriter, lat, lng float32) {