PKGBUILD/pkg/logger/logger.go

74 lines
1.8 KiB
Go
Raw Normal View History

2019-03-04 09:45:00 +00:00
package logger
import (
2019-03-04 19:52:41 +00:00
"fmt"
2019-03-04 16:45:46 +00:00
"time"
2019-03-04 09:45:00 +00:00
"git.cryptic.systems/fh-trier/go-flucky/pkg/types"
)
type Logger interface {
2019-03-04 16:45:46 +00:00
GetHumidities(fromDate *time.Time, tillDate *time.Time, sensorNameOrUUID *[]string) ([]*types.Humidity, error)
2019-03-04 16:56:49 +00:00
GetTemperatures(from *time.Time, till *time.Time, sensorIDs []string) ([]*types.Temperature, error)
2019-03-04 09:45:00 +00:00
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"
)
2019-03-04 19:52:41 +00:00
// 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)
}
}