diff --git a/main.go b/main.go index 4049160..c5d7a9d 100644 --- a/main.go +++ b/main.go @@ -2,27 +2,30 @@ package main import ( "fmt" - "net/http" - "github.com/csfreak/weather_station/weather" + "log" + "net/http" ) +var apiListenerPort = ":8080" + func main() { - fmt.Println("Staring main func") http.HandleFunc("/v1/ecowitt", ecowittHandler) http.HandleFunc("/v1/ecowitt/", ecowittHandler) - fmt.Println("Starting HTTP Server") - err := http.ListenAndServe(":8080", nil) - fmt.Println(err) - fmt.Println("After HTTP Server") + fmt.Println("Starting HTTP Server on", apiListenerPort) + log.Fatal(http.ListenAndServe(apiListenerPort, nil)) } func ecowittHandler(res http.ResponseWriter, req *http.Request) { if !(req.Method == http.MethodPost) { res.WriteHeader(http.StatusMethodNotAllowed) } else { - req.ParseForm() + parseErr := req.ParseForm() + if parseErr != nil { + fmt.Println(parseErr) + return + } fmt.Println(req.PostForm) w, err := weather.FromEcowitt(req.PostForm) if err != nil {