fix(pkg/config): use storage endpoints

changes:
- Only one storage endpoint can be defined. This consists of a URL which
  can be used to specify whether the data is to be stored in a file or
  in a database.
This commit is contained in:
2019-12-07 16:53:49 +01:00
parent afe55b3d33
commit dbef4f8241
30 changed files with 959 additions and 882 deletions

View File

@ -94,7 +94,7 @@ func (s *BME280) Read() ([]*types.MeasuredValue, error) {
// ReadChannel reads the measured values from the sensor and writes them to a
// channel.
func (s *BME280) ReadChannel(measuredValuesChannel chan<- []*types.MeasuredValue, errorChannel chan<- error, wg *sync.WaitGroup) {
func (s *BME280) ReadChannel(measuredValueChannel chan<- *types.MeasuredValue, errorChannel chan<- error, wg *sync.WaitGroup) {
if wg != nil {
defer wg.Done()
}
@ -105,20 +105,22 @@ func (s *BME280) ReadChannel(measuredValuesChannel chan<- []*types.MeasuredValue
return
}
measuredValuesChannel <- measuredValues
for _, measuredValue := range measuredValues {
measuredValueChannel <- measuredValue
}
}
// ReadContinously reads the measured values continously from the sensor and
// writes them to a channel.
func (s *BME280) ReadContinously(ctx context.Context, measuredValuesChannel chan<- []*types.MeasuredValue, errorChannel chan<- error) {
func (s *BME280) ReadContinously(ctx context.Context, measuredValueChannel chan<- *types.MeasuredValue, errorChannel chan<- error) {
for {
select {
case <-ctx.Done():
errorChannel <- fmt.Errorf("%v: Context closed: %v", s.SensorName, ctx.Err())
return
default:
s.ReadChannel(measuredValuesChannel, errorChannel, nil)
s.ReadChannel(measuredValueChannel, errorChannel, nil)
}
}
}

View File

@ -68,7 +68,7 @@ func (s *DHT11) Read() ([]*types.MeasuredValue, error) {
// ReadChannel reads the measured values from the sensor and writes them to a
// channel.
func (s *DHT11) ReadChannel(measuredValuesChannel chan<- []*types.MeasuredValue, errorChannel chan<- error, wg *sync.WaitGroup) {
func (s *DHT11) ReadChannel(measuredValueChannel chan<- *types.MeasuredValue, errorChannel chan<- error, wg *sync.WaitGroup) {
if wg != nil {
defer wg.Done()
}
@ -79,20 +79,22 @@ func (s *DHT11) ReadChannel(measuredValuesChannel chan<- []*types.MeasuredValue,
return
}
measuredValuesChannel <- measuredValues
for _, measuredValue := range measuredValues {
measuredValueChannel <- measuredValue
}
}
// ReadContinously reads the measured values continously from the sensor and
// writes them to a channel.
func (s *DHT11) ReadContinously(ctx context.Context, measuredValuesChannel chan<- []*types.MeasuredValue, errorChannel chan<- error) {
func (s *DHT11) ReadContinously(ctx context.Context, measuredValueChannel chan<- *types.MeasuredValue, errorChannel chan<- error) {
for {
select {
case <-ctx.Done():
errorChannel <- fmt.Errorf("%v: Context closed: %v", s.SensorName, ctx.Err())
return
default:
s.ReadChannel(measuredValuesChannel, errorChannel, nil)
s.ReadChannel(measuredValueChannel, errorChannel, nil)
}
}
}

View File

@ -68,7 +68,7 @@ func (s *DHT22) Read() ([]*types.MeasuredValue, error) {
// ReadChannel reads the measured values from the sensor and writes them to a
// channel.
func (s *DHT22) ReadChannel(measuredValuesChannel chan<- []*types.MeasuredValue, errorChannel chan<- error, wg *sync.WaitGroup) {
func (s *DHT22) ReadChannel(measuredValueChannel chan<- *types.MeasuredValue, errorChannel chan<- error, wg *sync.WaitGroup) {
if wg != nil {
defer wg.Done()
}
@ -79,20 +79,22 @@ func (s *DHT22) ReadChannel(measuredValuesChannel chan<- []*types.MeasuredValue,
return
}
measuredValuesChannel <- measuredValues
for _, measuredValue := range measuredValues {
measuredValueChannel <- measuredValue
}
}
// ReadContinously reads the measured values continously from the sensor and
// writes them to a channel.
func (s *DHT22) ReadContinously(ctx context.Context, measuredValuesChannel chan<- []*types.MeasuredValue, errorChannel chan<- error) {
func (s *DHT22) ReadContinously(ctx context.Context, measuredValueChannel chan<- *types.MeasuredValue, errorChannel chan<- error) {
for {
select {
case <-ctx.Done():
errorChannel <- fmt.Errorf("%v: Context closed: %v", s.SensorName, ctx.Err())
return
default:
s.ReadChannel(measuredValuesChannel, errorChannel, nil)
s.ReadChannel(measuredValueChannel, errorChannel, nil)
}
}
}

View File

@ -67,7 +67,7 @@ func (s *DS18B20) Read() ([]*types.MeasuredValue, error) {
// ReadChannel reads the measured values from the sensor and writes them to a
// channel.
func (s *DS18B20) ReadChannel(measuredValuesChannel chan<- []*types.MeasuredValue, errorChannel chan<- error, wg *sync.WaitGroup) {
func (s *DS18B20) ReadChannel(measuredValueChannel chan<- *types.MeasuredValue, errorChannel chan<- error, wg *sync.WaitGroup) {
if wg != nil {
defer wg.Done()
}
@ -78,20 +78,22 @@ func (s *DS18B20) ReadChannel(measuredValuesChannel chan<- []*types.MeasuredValu
return
}
measuredValuesChannel <- measuredValues
for _, measuredValue := range measuredValues {
measuredValueChannel <- measuredValue
}
}
// ReadContinously reads the measured values continously from the sensor and
// writes them to a channel.
func (s *DS18B20) ReadContinously(ctx context.Context, measuredValuesChannel chan<- []*types.MeasuredValue, errorChannel chan<- error) {
func (s *DS18B20) ReadContinously(ctx context.Context, measuredValueChannel chan<- *types.MeasuredValue, errorChannel chan<- error) {
for {
select {
case <-ctx.Done():
errorChannel <- fmt.Errorf("%v: Context closed: %v", s.SensorName, ctx.Err())
return
default:
s.ReadChannel(measuredValuesChannel, errorChannel, nil)
s.ReadChannel(measuredValueChannel, errorChannel, nil)
}
}
}

View File

@ -10,6 +10,6 @@ import (
type Sensor interface {
GetSensorModel() types.SensorModel
Read() ([]*types.MeasuredValue, error)
ReadChannel(measuredValuesChannel chan<- []*types.MeasuredValue, errorChannel chan<- error, wg *sync.WaitGroup)
ReadContinously(ctx context.Context, measuredValuesChannel chan<- []*types.MeasuredValue, errorChannel chan<- error)
ReadChannel(measuredValueChannel chan<- *types.MeasuredValue, errorChannel chan<- error, wg *sync.WaitGroup)
ReadContinously(ctx context.Context, measuredValueChannel chan<- *types.MeasuredValue, errorChannel chan<- error)
}

View File

@ -14,30 +14,30 @@ import (
// Read measured values from sensors
func Read(ctx context.Context, sensors []Sensor) ([]*types.MeasuredValue, error) {
measuredValuesChannel := make(chan []*types.MeasuredValue, len(sensors))
measuredValueChannel := make(chan *types.MeasuredValue, len(sensors))
errorChannel := make(chan error, len(sensors))
ReadChannel(ctx, sensors, measuredValuesChannel, errorChannel)
ReadChannel(ctx, sensors, measuredValueChannel, errorChannel)
errors := collect.Errors(errorChannel)
if len(errors) > 0 {
return nil, prittyprint.FormatErrors(errors)
}
measuredValues := collect.MeasuredValues(measuredValuesChannel)
measuredValues := collect.MeasuredValues(measuredValueChannel)
return measuredValues, nil
}
// ReadChannel reads the measured values from sensors and writes them to a
// channel.
func ReadChannel(ctx context.Context, sensors []Sensor, measuredValuesChannel chan<- []*types.MeasuredValue, errorChannel chan<- error) {
func ReadChannel(ctx context.Context, sensors []Sensor, measuredValueChannel chan<- *types.MeasuredValue, errorChannel chan<- error) {
wg := new(sync.WaitGroup)
wg.Add(len(sensors))
for _, sensor := range sensors {
go sensor.ReadChannel(measuredValuesChannel, errorChannel, wg)
go sensor.ReadChannel(measuredValueChannel, errorChannel, wg)
}
wg.Wait()
@ -45,14 +45,14 @@ func ReadChannel(ctx context.Context, sensors []Sensor, measuredValuesChannel ch
// ReadContinuously reads the measured values continously from sensors and writes
// them to a channel.
func ReadContinuously(ctx context.Context, sensors []Sensor, measuredValuesChannel chan<- []*types.MeasuredValue, errorChannel chan<- error) {
func ReadContinuously(ctx context.Context, sensors []Sensor, measuredValueChannel chan<- *types.MeasuredValue, errorChannel chan<- error) {
for {
select {
case <-ctx.Done():
errorChannel <- fmt.Errorf("Context closed: %v", ctx.Err())
return
default:
ReadChannel(ctx, sensors, measuredValuesChannel, errorChannel)
ReadChannel(ctx, sensors, measuredValueChannel, errorChannel)
}
}
}