fix: dependancies
This commit is contained in:
parent
4097c67a58
commit
54dd2191d6
4
Gopkg.lock
generated
4
Gopkg.lock
generated
@ -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"
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user