fix: dependancies

This commit is contained in:
Markus Pesch 2018-11-07 20:26:48 +01:00
parent 4097c67a58
commit 54dd2191d6
Signed by: volker.raschek
GPG Key ID: 852BCC170D81A982
2 changed files with 77 additions and 2 deletions

4
Gopkg.lock generated
View File

@ -3,11 +3,11 @@
[[projects]] [[projects]]
branch = "master" branch = "master"
digest = "1:3cefbd6fbf4b3a7a9f3490ce01ca41d792b0972d80122131f68897d122514a62" digest = "1:67bdb81292d46305e49b2c67585e9d4fbf6832aa86be02e27081fb3c171d6cdb"
name = "git.cryptic.systems/fh-trier/go-flucky-server" name = "git.cryptic.systems/fh-trier/go-flucky-server"
packages = ["pkg/types"] packages = ["pkg/types"]
pruneopts = "UT" pruneopts = "UT"
revision = "4f5093d13415b9865eeedf495f75c46c566a4378" revision = "71ed96f2661f290526cb151fd02a2c561452d6ae"
[[projects]] [[projects]]
digest = "1:870d441fe217b8e689d7949fef6e43efbc787e50f200cb1e70dbca9204a1d6be" digest = "1:870d441fe217b8e689d7949fef6e43efbc787e50f200cb1e70dbca9204a1d6be"

View File

@ -1,9 +1,43 @@
package types package types
import (
"encoding/json"
"fmt"
"io"
)
// TypeObject ...
type TypeObject interface {
EncodeToJSON(w io.Writer) error
DecodeFromJSON(r io.Reader) error
}
// Device ...
type Device struct { type Device struct {
DeviceID string `json:"device_id"` DeviceID string `json:"device_id"`
} }
// 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("", " ")
err := encoder.Encode(&d)
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 (d *Device) DecodeFromJSON(r io.Reader) error {
decoder := json.NewDecoder(r)
if err := decoder.Decode(&d); err != nil {
return fmt.Errorf("Can not unmarshal JSON: %v", err)
}
return nil
}
// Humidity ...
type Humidity struct { type Humidity struct {
HumidityID string `json:"humidity_id"` HumidityID string `json:"humidity_id"`
HumidityValue string `json:"humidity_value"` HumidityValue string `json:"humidity_value"`
@ -11,9 +45,50 @@ type Humidity struct {
DeviceID string `json:"device_id"` DeviceID string `json:"device_id"`
} }
// 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("", " ")
err := encoder.Encode(&h)
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 (h *Humidity) DecodeFromJSON(r io.Reader) error {
decoder := json.NewDecoder(r)
if err := decoder.Decode(&h); err != nil {
return fmt.Errorf("Can not unmarshal JSON: %v", err)
}
return nil
}
// Temperature ...
type Temperature struct { type Temperature struct {
TemperatureID string `json:"temperature_id"` TemperatureID string `json:"temperature_id"`
TemperatureValue string `json:"temperature_value"` TemperatureValue string `json:"temperature_value"`
TemperatureDate string `json:"temperature_date"` TemperatureDate string `json:"temperature_date"`
DeviceID string `json:"device_id"` DeviceID string `json:"device_id"`
} }
// 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("", " ")
err := encoder.Encode(&t)
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 (t *Temperature) DecodeFromJSON(r io.Reader) error {
decoder := json.NewDecoder(r)
if err := decoder.Decode(&t); err != nil {
return fmt.Errorf("Can not unmarshal JSON: %v", err)
}
return nil
}