Skip to content

Commit

Permalink
Clean some logging and printing, add some ease of life decoupling (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
MightyDjinn authored Dec 13, 2021
1 parent 2ad0053 commit e0b0ccb
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e0b0ccb

Please sign in to comment.