fix: config, device_name and device_location
This commit is contained in:
@ -6,19 +6,25 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/satori/go.uuid"
|
||||
|
||||
"git.cryptic.systems/fh-trier/go-flucky/pkg/types"
|
||||
|
||||
"github.com/satori/go.uuid"
|
||||
)
|
||||
|
||||
var configFilename = "config.json"
|
||||
var humiditiesLogfileName = "humidities.log"
|
||||
var temperatureLogfileName = "temperature.log"
|
||||
|
||||
func Create(configDir string, force bool) error {
|
||||
func Create(configDir, logDir string, force bool) error {
|
||||
|
||||
configPath := filepath.Join(configDir, configFilename)
|
||||
humiditiesLogfile := filepath.Join(logDir, humiditiesLogfileName)
|
||||
temperaturLogfile := filepath.Join(logDir, temperatureLogfileName)
|
||||
|
||||
config := &types.Config{
|
||||
DeviceID: uuid.NewV4().String(),
|
||||
DeviceID: uuid.NewV4().String(),
|
||||
HumidityLogfile: humiditiesLogfile,
|
||||
TemperatureLogfile: temperaturLogfile,
|
||||
}
|
||||
|
||||
// If no config file exists, create a new one on the location
|
||||
@ -47,6 +53,38 @@ func Create(configDir string, force bool) error {
|
||||
|
||||
}
|
||||
|
||||
func DeviceName(deviceName, configDir string) error {
|
||||
cnf, err := Read(configDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cnf.DeviceName = deviceName
|
||||
|
||||
err = Write(cnf, configDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func DeviceLocation(deviceLocation, configDir string) error {
|
||||
cnf, err := Read(configDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cnf.DeviceLocation = deviceLocation
|
||||
|
||||
err = Write(cnf, configDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func Read(configDir string) (*types.Config, error) {
|
||||
|
||||
configPath := filepath.Join(configDir, configFilename)
|
||||
|
Reference in New Issue
Block a user