finding a bug

This commit is contained in:
Daniel Ledda
2020-11-01 01:44:31 +01:00
parent 746e1010fa
commit 45b3cea9a1

View File

@@ -47,7 +47,10 @@ func main() {
} }
func viewHandler(w http.ResponseWriter, r *http.Request) { func viewHandler(w http.ResponseWriter, r *http.Request) {
fmt.Println(r.Method) switch r.Method {
case "GET":
_, _ = fmt.Fprint(w, "<h1>Climate Stuff</h1><div>The data will show up here at some stage...</div>")
case "POST":
var snapshotSub SnapshotSubmission var snapshotSub SnapshotSubmission
body, err := ioutil.ReadAll(r.Body) body, err := ioutil.ReadAll(r.Body)
if err != nil { if err != nil {
@@ -57,5 +60,11 @@ func viewHandler(w http.ResponseWriter, r *http.Request) {
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
_, _ = fmt.Fprint(w, "<h1>Climate Stuff</h1><div>The data will show up here at some stage...</div>") _, _ = climateDb.Query(
"INSERT INTO `snapshots` (`temp`, `humidity`, `co2`, `time`, `id`) VALUES (%v, %v, %v, %v, NULL);",
snapshotSub.Temp,
snapshotSub.Humidity,
snapshotSub.Timestamp,
snapshotSub.Co2)
}
} }