74 lines
1.8 KiB
Go
74 lines
1.8 KiB
Go
package logger
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"git.cryptic.systems/fh-trier/go-flucky/pkg/types"
|
|
)
|
|
|
|
type Logger interface {
|
|
GetHumidities(fromDate *time.Time, tillDate *time.Time, sensorNameOrUUID *[]string) ([]*types.Humidity, error)
|
|
GetTemperatures(from *time.Time, till *time.Time, sensorIDs []string) ([]*types.Temperature, error)
|
|
LogHumidities(humidities []*types.Humidity) error
|
|
LogTemperatures(temperatures []*types.Temperature) error
|
|
}
|
|
|
|
type LoggerType string
|
|
|
|
const (
|
|
LogFile LoggerType = "file"
|
|
LogRemote = "remote"
|
|
)
|
|
|
|
type LogValue string
|
|
|
|
const (
|
|
LogHumidity LogValue = "humidity"
|
|
LogTemperature = "temperature"
|
|
)
|
|
|
|
// LogTypeToString converts a logtype into a string
|
|
func LogTypeToString(loggertype LoggerType) (string, error) {
|
|
switch loggertype {
|
|
case LogFile:
|
|
return "file", nil
|
|
default:
|
|
return "", fmt.Errorf("Can not determine loggertype %v", loggertype)
|
|
}
|
|
}
|
|
|
|
// LogValueToString converts a logvalue into a string
|
|
func LogValueToString(logvalue LogValue) (string, error) {
|
|
switch logvalue {
|
|
case LogHumidity:
|
|
return "humidity", nil
|
|
case LogTemperature:
|
|
return "temperature", nil
|
|
default:
|
|
return "", fmt.Errorf("Can not determine logvalue %v", logvalue)
|
|
}
|
|
}
|
|
|
|
// StringToLoggerType converts a string into loggertype
|
|
func StringToLoggerType(loggertype string) (LoggerType, error) {
|
|
switch loggertype {
|
|
case "file":
|
|
return LogFile, nil
|
|
default:
|
|
return "", fmt.Errorf("Can not determine loggertype %v", loggertype)
|
|
}
|
|
}
|
|
|
|
// StringToLogValue converts a string into logvalue
|
|
func StringToLogValue(logvalue string) (LogValue, error) {
|
|
switch logvalue {
|
|
case "humidity":
|
|
return LogHumidity, nil
|
|
case "temperature":
|
|
return LogTemperature, nil
|
|
default:
|
|
return "", fmt.Errorf("Can not determine logvalue %v", logvalue)
|
|
}
|
|
}
|