WIP
This commit is contained in:
@ -15,11 +15,13 @@ type TypeObject interface {
|
||||
|
||||
// Device ...
|
||||
type Device struct {
|
||||
DeviceID string `json:"device_id"`
|
||||
CreationDate time.Time `json:"creation_date"`
|
||||
DeviceID string `json:"device_id"`
|
||||
DeviceName *string `json:"device_name"`
|
||||
DeviceLocation *string `json:"device_location"`
|
||||
CreationDate time.Time `json:"creation_date"`
|
||||
}
|
||||
|
||||
// EncodeToJson needs a writer to write the struct into json string
|
||||
// EncodeToJSON needs a writer to write the struct into json string
|
||||
func (d *Device) EncodeToJSON(w io.Writer) error {
|
||||
encoder := json.NewEncoder(w)
|
||||
encoder.SetIndent("", " ")
|
||||
@ -30,7 +32,7 @@ func (d *Device) EncodeToJSON(w io.Writer) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// DecodeFromJson decode a json string from a reader into a struct
|
||||
// DecodeFromJSON decode a json string from a reader into a struct
|
||||
func (d *Device) DecodeFromJSON(r io.Reader) error {
|
||||
decoder := json.NewDecoder(r)
|
||||
if err := decoder.Decode(&d); err != nil {
|
||||
@ -41,15 +43,14 @@ func (d *Device) DecodeFromJSON(r io.Reader) error {
|
||||
|
||||
// Humidity ...
|
||||
type Humidity struct {
|
||||
HumidityID string `json:"humidity_id"`
|
||||
HumidityValue json.Number `json:"humidity_value"`
|
||||
HumidityDate time.Time `json:"humidity_date"`
|
||||
SensorID string `json:"sensor_id"`
|
||||
DeviceID string `json:"device_id"`
|
||||
CreationDate time.Time `json:"creation_date"`
|
||||
HumidityID string `json:"humidity_id"`
|
||||
HumidityValue float64 `json:"humidity_value,string"`
|
||||
HumidityDate time.Time `json:"humidity_date"`
|
||||
SensorID string `json:"sensor_id"`
|
||||
CreationDate time.Time `json:"creation_date"`
|
||||
}
|
||||
|
||||
// EncodeToJson needs a writer to write the struct into json string
|
||||
// EncodeToJSON needs a writer to write the struct into json string
|
||||
func (h *Humidity) EncodeToJSON(w io.Writer) error {
|
||||
encoder := json.NewEncoder(w)
|
||||
encoder.SetIndent("", " ")
|
||||
@ -60,7 +61,7 @@ func (h *Humidity) EncodeToJSON(w io.Writer) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// DecodeFromJson decode a json string from a reader into a struct
|
||||
// DecodeFromJSON decode a json string from a reader into a struct
|
||||
func (h *Humidity) DecodeFromJSON(r io.Reader) error {
|
||||
decoder := json.NewDecoder(r)
|
||||
if err := decoder.Decode(&h); err != nil {
|
||||
@ -69,17 +70,48 @@ func (h *Humidity) DecodeFromJSON(r io.Reader) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Sensor ...
|
||||
type Sensor struct {
|
||||
SensorID string `json:"sensor_id"`
|
||||
SensorName *string `json:"sensor_name"`
|
||||
SensorLocation *string `json:"sensor_location"`
|
||||
WireID *string `json:"wire_id"`
|
||||
GPIONumber *string `json:"gpio_number"`
|
||||
SensorType *string `json:"sensor_type"`
|
||||
DeviceID string `json:"device_id"`
|
||||
CreationDate time.Time `json:"creation_date"`
|
||||
}
|
||||
|
||||
// EncodeToJSON needs a writer to write the struct into json string
|
||||
func (s *Sensor) EncodeToJSON(w io.Writer) error {
|
||||
encoder := json.NewEncoder(w)
|
||||
encoder.SetIndent("", " ")
|
||||
err := encoder.Encode(&s)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error in encoding struct to json: %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DecodeFromJSON decode a json string from a reader into a struct
|
||||
func (s *Sensor) DecodeFromJSON(r io.Reader) error {
|
||||
decoder := json.NewDecoder(r)
|
||||
if err := decoder.Decode(&s); err != nil {
|
||||
return fmt.Errorf("Can not unmarshal JSON: %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Temperature ...
|
||||
type Temperature struct {
|
||||
TemperatureID string `json:"temperature_id"`
|
||||
TemperatureValue float64 `json:"temperature_value,string"`
|
||||
TemperatureDate time.Time `json:"temperature_date"`
|
||||
SensorID string `json:"sensor_id"`
|
||||
DeviceID string `json:"device_id"`
|
||||
CreationDate time.Time `json:"creation_date"`
|
||||
}
|
||||
|
||||
// EncodeToJson needs a writer to write the struct into json string
|
||||
// EncodeToJSON needs a writer to write the struct into json string
|
||||
func (t *Temperature) EncodeToJSON(w io.Writer) error {
|
||||
encoder := json.NewEncoder(w)
|
||||
encoder.SetIndent("", " ")
|
||||
@ -90,7 +122,7 @@ func (t *Temperature) EncodeToJSON(w io.Writer) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// DecodeFromJson decode a json string from a reader into a struct
|
||||
// DecodeFromJSON decode a json string from a reader into a struct
|
||||
func (t *Temperature) DecodeFromJSON(r io.Reader) error {
|
||||
decoder := json.NewDecoder(r)
|
||||
if err := decoder.Decode(&t); err != nil {
|
||||
|
Reference in New Issue
Block a user