finding a bug
This commit is contained in:
22
server.go
22
server.go
@@ -1,9 +1,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"database/sql"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
@@ -11,7 +13,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Snapshot struct {
|
||||
type SnapshotRecord struct {
|
||||
Id int
|
||||
Timestamp time.Time
|
||||
Temp float32
|
||||
@@ -19,6 +21,14 @@ type Snapshot struct {
|
||||
Co2 float32
|
||||
}
|
||||
|
||||
type SnapshotSubmission struct {
|
||||
Timestamp time.Time `json:"time"`
|
||||
Temp float32 `json:"temp"`
|
||||
Humidity float32 `json:"humidity"`
|
||||
Co2 float32 `json:"co2"`
|
||||
}
|
||||
|
||||
|
||||
var climateDb *sql.DB
|
||||
|
||||
func setupDb() *sql.DB {
|
||||
@@ -39,11 +49,15 @@ func main() {
|
||||
|
||||
func viewHandler(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Println("Request received")
|
||||
reqBody, err := ioutil.ReadAll(r.Body)
|
||||
var snapshotSub SnapshotSubmission
|
||||
body, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Printf("%s\n", reqBody)
|
||||
err = json.Unmarshal(body, &snapshotSub)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Printf("%v\n", snapshotSub)
|
||||
_, _ = 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