This commit is contained in:
Daniel Ledda
2020-11-04 18:08:42 +01:00
parent fccba1e4d7
commit cc8cd4bbc4
3 changed files with 54 additions and 14 deletions

View File

@@ -5,15 +5,11 @@ import (
"fmt"
"io"
"io/ioutil"
"time"
)
type SnapshotRecord struct {
Id int
Timestamp time.Time
Temp float32
Humidity float32
Co2 float32
Id int `json:"id"`
SnapshotSubmission
}
type SnapshotSubmission struct {
@@ -23,7 +19,7 @@ type SnapshotSubmission struct {
Co2 float32 `json:"co2"`
}
func createSnapshotFromJson(jsonBodyStream io.ReadCloser) (*SnapshotSubmission, error) {
func createSnapshotSubFromJsonBodyStream(jsonBodyStream io.ReadCloser) (*SnapshotSubmission, error) {
var snapshotSub SnapshotSubmission
body, err := ioutil.ReadAll(jsonBodyStream)
if err != nil {
@@ -38,4 +34,12 @@ func createSnapshotFromJson(jsonBodyStream io.ReadCloser) (*SnapshotSubmission,
return nil, fmt.Errorf("couldn't unmarshal json: %w", err)
}
return &snapshotSub, nil
}
func createJsonFromSnapshotRecords(records []*SnapshotRecord) ([]byte, error) {
jsonResult, err := json.Marshal(records)
if err != nil {
return nil, err
}
return jsonResult, nil
}