feat(daemon): add new subcommand to start a daemon
This commit is contained in:
@ -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)
|
||||
|
Reference in New Issue
Block a user