finding a bug
This commit is contained in:
29
server.go
29
server.go
@@ -47,15 +47,24 @@ func main() {
|
||||
}
|
||||
|
||||
func viewHandler(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Println(r.Method)
|
||||
var snapshotSub SnapshotSubmission
|
||||
body, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
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
|
||||
body, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = json.Unmarshal(body, &snapshotSub)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
_, _ = climateDb.Query(
|
||||
"INSERT INTO `snapshots` (`temp`, `humidity`, `co2`, `time`, `id`) VALUES (%v, %v, %v, %v, NULL);",
|
||||
snapshotSub.Temp,
|
||||
snapshotSub.Humidity,
|
||||
snapshotSub.Timestamp,
|
||||
snapshotSub.Co2)
|
||||
}
|
||||
err = json.Unmarshal(body, &snapshotSub)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
_, _ = fmt.Fprint(w, "<h1>Climate Stuff</h1><div>The data will show up here at some stage...</div>")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user