From 8613938d8e7c077ba9ea8a385a4820993b54dc89 Mon Sep 17 00:00:00 2001 From: Boernsman <5207214+Boernsman@users.noreply.github.com> Date: Tue, 24 Sep 2024 12:01:48 +0200 Subject: [PATCH] Fix flag parsing --- main.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/main.go b/main.go index 13005b0..71e1d30 100644 --- a/main.go +++ b/main.go @@ -12,6 +12,7 @@ import ( "time" ) + const lifetime time.Duration = 24 * time.Hour var devices struct { @@ -32,6 +33,14 @@ func main() { publicFolder := flag.String("public", "./public/", "Folder with the public files") httpPort := flag.String("http-port", "8180", "Port for the HTTP server") + // Parse the command-line flags + flag.Parse() + + // Check if the pubic folder exists + if _, err := os.Stat(*publicFolder); os.IsNotExist(err) { + log.Fatalf("Publich folder does not exist") + } + devices.d = make([]Device, 0) http.HandleFunc("/favicon.ico", func(w http.ResponseWriter, r *http.Request) {}) @@ -42,6 +51,8 @@ func main() { go cleanup() fmt.Println("Listen on port", httpPort) + fmt.Println("Using public folder", publicFolder) + // Note: use TLS log.Fatal(http.ListenAndServe(":" + *httpPort, nil)) }