package main import ( "github.com/aws/aws-sdk-go/service/dynamodb" "github.com/aws/aws-sdk-go/service/dynamodb/dynamodbattribute" ) // Device struct for store device data from iot-item table type Device struct { Device string `json:"device"` Name string `json:"name"` Model string `json:"model"` } // ItemInfo - create structs to hold info about new item type ItemInfo struct { Firmware string `json:"firmware"` Sensor string `json:"sensor"` Model string `json:"model"` Name string `json:"name"` } // SensorData to store all sensor's data type SensorData struct { Battery int `json:"battery"` Light int `json:"light"` Conductivity float32 `json:"conductivity"` Moisture float32 `json:"moisture"` Temperature float32 `json:"temperature"` Humidity float32 `json:"humidity"` } // Item is an item to generalize every IoT devices type Item struct { Device string `json:"device"` Timestamp string `json:"timestamp"` Info ItemInfo `json:"info"` Data SensorData `json:"data"` } // History returns data in []Item func (d Device) History(svc *dynamodb.DynamoDB, limit int64) ([]Item, error) { result, err := GetHistory(svc, d.Device, limit) var ev []Item if err != nil { return ev, err } for _, i := range result.Items { item := Item{} err = dynamodbattribute.UnmarshalMap(i, &item) item.Info.Name = d.Name item.Info.Model = d.Model if err != nil { return ev, err } ev = append(ev, item) } return ev, nil }