fix: breaking changes

changes:
- remove remote operations
- add function to write measured values into a channel
- add get humidity sensors from config
- add get temperature sensors from config
- remove FileLogger
- exclude some functions from pkf into internal
This commit is contained in:
2019-06-13 21:25:32 +02:00
parent 98e5f3a536
commit 5220eac16b
39 changed files with 481 additions and 1376 deletions

View File

@ -1,6 +1,7 @@
package config
import (
"encoding/json"
"fmt"
"os"
"path/filepath"
@ -10,9 +11,9 @@ import (
var validUUID = regexp.MustCompile("^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$")
// Read the configuration file
func Read(configFile string) (*FluckyConfig, error) {
func Read(configFile string) (*Configuration, error) {
fc := &FluckyConfig{}
fc := &Configuration{}
f, err := os.Open(configFile)
if err != nil {
@ -20,9 +21,9 @@ func Read(configFile string) (*FluckyConfig, error) {
}
defer f.Close()
err = fc.JSONDecoder(f)
if err != nil {
return nil, fmt.Errorf("Can not decode json file %v: %v", configFile, err)
jsonDecoder := json.NewDecoder(f)
if err := jsonDecoder.Decode(&fc); err != nil {
return nil, fmt.Errorf("Can not unmarshal JSON: %v", err)
}
return fc, nil
@ -30,7 +31,7 @@ func Read(configFile string) (*FluckyConfig, error) {
}
// Write the configuration into a file, specified by the configuration filepath
func Write(cfg *FluckyConfig, configFile string) error {
func Write(cfg *Configuration, configFile string) error {
if _, err := os.Stat(configFile); os.IsNotExist(err) {
configDir := filepath.Dir(configFile)
@ -46,9 +47,11 @@ func Write(cfg *FluckyConfig, configFile string) error {
}
defer f.Close()
err = cfg.JSONWriter(f)
encoder := json.NewEncoder(f)
encoder.SetIndent("", " ")
err = encoder.Encode(cfg)
if err != nil {
return err
return fmt.Errorf("Error in encoding struct to json: %v", err)
}
return nil