big update

This commit is contained in:
Daniel Ledda
2021-02-27 13:06:36 +01:00
parent 0dc3fdb9b8
commit eb5c9faa35
13 changed files with 746 additions and 169 deletions

View File

@@ -7,11 +7,19 @@ import (
"io/ioutil"
)
type SnapshotPayload struct {
Snapshots []*SnapshotRecord `json:"snapshots"`
type UnixSnapshotPayload struct {
Snapshots []*UnixSnapshotRecord `json:"snapshots"`
}
type SnapshotRecord struct {
type DatetimeSnapshotPayload struct {
Snapshots []*DatetimeSnapshotRecord `json:"snapshots"`
}
type UnixSnapshotRecord struct {
}
type DatetimeSnapshotRecord struct {
Id int `json:"id"`
JsonSnapshotSubmission
}
@@ -30,8 +38,8 @@ type SnapshotSubmission struct {
Co2 interface{}
}
func createSnapshotSubFromJsonBodyStream(jsonBodyStream io.ReadCloser) (*SnapshotSubmission, error) {
var snapshotSub SnapshotSubmission
func createSnapshotSubFromJsonBodyStream(jsonBodyStream io.ReadCloser) (*JsonSnapshotSubmission, error) {
var snapshotSub JsonSnapshotSubmission
body, err := ioutil.ReadAll(jsonBodyStream)
if err != nil {
return nil, fmt.Errorf("error reading body stream: %w", err)
@@ -47,8 +55,8 @@ func createSnapshotSubFromJsonBodyStream(jsonBodyStream io.ReadCloser) (*Snapsho
return &snapshotSub, nil
}
func createJsonFromSnapshotRecords(records []*SnapshotRecord) ([]byte, error) {
jsonResult, err := json.Marshal(SnapshotPayload{records})
func createJsonFromSnapshotRecords(records []*DatetimeSnapshotRecord) ([]byte, error) {
jsonResult, err := json.Marshal(DatetimeSnapshotPayload{records})
if err != nil {
return nil, fmt.Errorf("couldn't marshal json: %w", err)
}