refactor: config and remote pkg
This commit is contained in:
@ -2,33 +2,12 @@ package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"regexp"
|
||||
|
||||
"git.cryptic.systems/fh-trier/go-flucky-server/pkg/types"
|
||||
)
|
||||
|
||||
var validUUID = regexp.MustCompile("^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$")
|
||||
|
||||
type Config interface {
|
||||
AddSensor(sensor *types.Sensor) error
|
||||
AddRemote(remote *Remote) error
|
||||
DisableRemote(nameOrUUID string) error
|
||||
DisableSensor(nameOrUUID string) error
|
||||
EnableRemote(nameOrUUID string) error
|
||||
EnableSensor(nameOrUUID string) error
|
||||
GetDevice() *Device
|
||||
GetRemotes() []*Remote
|
||||
GetSensors() []*types.Sensor
|
||||
JSONDecoder(r io.Reader) error
|
||||
JSONWriter(w io.Writer) error
|
||||
RemoveSensor(nameOrUUID string) error
|
||||
RemoveRemote(nameOrUUID string) error
|
||||
SetDevice(device *Device)
|
||||
ToJSON() (string, error)
|
||||
}
|
||||
|
||||
// Read the configuration file
|
||||
func Read(configFile string) (*FluckyConfig, error) {
|
||||
|
||||
@ -50,7 +29,7 @@ func Read(configFile string) (*FluckyConfig, error) {
|
||||
}
|
||||
|
||||
// Write the configuration into a file, specified by the configuration filepath
|
||||
func Write(cfg Config, configFile string) error {
|
||||
func Write(cfg *FluckyConfig, configFile string) error {
|
||||
|
||||
f, err := os.Create(configFile)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user