From 54dd2191d62f91cf15ddd80e76f1aa637b79463c Mon Sep 17 00:00:00 2001 From: Markus Pesch Date: Wed, 7 Nov 2018 20:26:48 +0100 Subject: [PATCH] fix: dependancies --- Gopkg.lock | 4 +- .../go-flucky-server/pkg/types/types.go | 75 +++++++++++++++++++ 2 files changed, 77 insertions(+), 2 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 9c91278..4dc1db1 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -3,11 +3,11 @@ [[projects]] branch = "master" - digest = "1:3cefbd6fbf4b3a7a9f3490ce01ca41d792b0972d80122131f68897d122514a62" + digest = "1:67bdb81292d46305e49b2c67585e9d4fbf6832aa86be02e27081fb3c171d6cdb" name = "git.cryptic.systems/fh-trier/go-flucky-server" packages = ["pkg/types"] pruneopts = "UT" - revision = "4f5093d13415b9865eeedf495f75c46c566a4378" + revision = "71ed96f2661f290526cb151fd02a2c561452d6ae" [[projects]] digest = "1:870d441fe217b8e689d7949fef6e43efbc787e50f200cb1e70dbca9204a1d6be" diff --git a/vendor/git.cryptic.systems/fh-trier/go-flucky-server/pkg/types/types.go b/vendor/git.cryptic.systems/fh-trier/go-flucky-server/pkg/types/types.go index 6a47cde..de9a099 100644 --- a/vendor/git.cryptic.systems/fh-trier/go-flucky-server/pkg/types/types.go +++ b/vendor/git.cryptic.systems/fh-trier/go-flucky-server/pkg/types/types.go @@ -1,9 +1,43 @@ 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 { 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 { HumidityID string `json:"humidity_id"` HumidityValue string `json:"humidity_value"` @@ -11,9 +45,50 @@ type Humidity struct { 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 { TemperatureID string `json:"temperature_id"` TemperatureValue string `json:"temperature_value"` TemperatureDate string `json:"temperature_date"` 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 +}