From cabb2c77b393a385982b87c29ce8b14c2b58cb98 Mon Sep 17 00:00:00 2001 From: c1982 Date: Mon, 17 May 2021 22:26:02 +0300 Subject: [PATCH] feat: added address flag --- main.go | 11 ++++++++--- web.go | 7 +++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 8cd42e7..aaa8e5b 100644 --- a/main.go +++ b/main.go @@ -1,8 +1,13 @@ package main -import "fmt" +import ( + "flag" + "fmt" +) func main() { - fmt.Println("http://localhost:8000") - RunPage() + address := flag.String("address", "localhost:8080", "--address=:8080 or --address=192.168.1.10:80") + flag.Parse() + fmt.Printf("http://%s\r\n", *address) + RunPage(*address) } diff --git a/web.go b/web.go index 737f22a..f5944d6 100644 --- a/web.go +++ b/web.go @@ -13,7 +13,7 @@ import ( //go:embed pages/index.html var IndexPage string -func RunPage() { +func RunPage(address string) { http.HandleFunc("/datatransfers", func(w http.ResponseWriter, r *http.Request) { billdate := r.URL.Query().Get("date") if billdate == "" { @@ -57,7 +57,10 @@ func RunPage() { fmt.Fprintf(w, "%s", IndexPage) }) - http.ListenAndServe(":8000", nil) + err := http.ListenAndServe(address, nil) + if err != nil { + log.Fatal(err) + } } func GetDates(billdate string) (startdate, enddate string, err error) {