feat(daemon): add new subcommand to start a daemon

This commit is contained in:
2019-06-15 15:45:35 +02:00
parent 82faa1d536
commit 5f859139a4
4 changed files with 80 additions and 19 deletions

View File

@ -74,6 +74,20 @@ func ReadTemperatures(temperatureLogfile string) ([]*types.Temperature, error) {
return temperatures, nil
}
func ReadTemperaturesChannel(temperatureChannel <-chan *types.Temperature) []*types.Temperature {
temperatures := make([]*types.Temperature, 0)
for {
select {
case temperature, more := <-temperatureChannel:
if more {
temperatures = append(temperatures, temperature)
}
default:
return temperatures
}
}
}
// ReadTemperaturesCustom from a custom reader and returns an array with
// temperatures
func ReadTemperaturesCustom(r io.Reader) ([]*types.Temperature, error) {
@ -172,7 +186,7 @@ func WriteTemperaturesCustom(temperatures []*types.Temperature, w io.Writer, com
writeCreationDate(temperatures)
jsonEncoder := json.NewEncoder(w)
jsonEncoder.SetIndent("", " ")
jsonEncoder.SetIndent("", " ")
err := jsonEncoder.Encode(temperatures)
if err != nil {
return fmt.Errorf("Can not encode temperatures: %v", err)