finding a bug
This commit is contained in:
13
server.go
13
server.go
@@ -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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user