remove error of new weather data callback
This commit is contained in:
parent
36462b4748
commit
5f58565a53
5 changed files with 11 additions and 23 deletions
|
@ -184,11 +184,7 @@ func (api *weatherRestApi) addWeatherDataHandler(w http.ResponseWriter, r *http.
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = api.addNewWeatherData(*weatherData)
|
api.addNewWeatherData(*weatherData)
|
||||||
if err != nil {
|
|
||||||
http.Error(w, "", http.StatusBadRequest)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
w.Header().Add("content-type", "application/json")
|
w.Header().Add("content-type", "application/json")
|
||||||
w.WriteHeader(http.StatusCreated)
|
w.WriteHeader(http.StatusCreated)
|
||||||
|
@ -336,6 +332,6 @@ func (api *weatherRestApi) AddNewWeatherDataCallback(callback weathersource.NewW
|
||||||
api.weatherSource.AddNewWeatherDataCallback(callback)
|
api.weatherSource.AddNewWeatherDataCallback(callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *weatherRestApi) addNewWeatherData(weatherData storage.WeatherData) error {
|
func (api *weatherRestApi) addNewWeatherData(weatherData storage.WeatherData) {
|
||||||
return api.weatherSource.NewWeatherData(weatherData)
|
api.weatherSource.NewWeatherData(weatherData)
|
||||||
}
|
}
|
||||||
|
|
10
main.go
10
main.go
|
@ -1,7 +1,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"weather-data/api"
|
"weather-data/api"
|
||||||
|
@ -54,12 +53,9 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleNewWeatherData(wd storage.WeatherData) error {
|
func handleNewWeatherData(wd storage.WeatherData) {
|
||||||
_, err := sensorRegistry.ResolveSensorById(wd.SensorId)
|
_, err := sensorRegistry.ResolveSensorById(wd.SensorId)
|
||||||
if !config.AllowUnregisteredSensors && err != nil {
|
if config.AllowUnregisteredSensors || err == nil {
|
||||||
log.Print("discarded invalid weatherdata")
|
weatherStorage.Save(wd)
|
||||||
return fmt.Errorf("could not resolve sensor")
|
|
||||||
}
|
}
|
||||||
weatherStorage.Save(wd)
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,6 +135,6 @@ func (source *mqttWeatherSource) AddNewWeatherDataCallback(callback NewWeatherDa
|
||||||
source.weatherSource.AddNewWeatherDataCallback(callback)
|
source.weatherSource.AddNewWeatherDataCallback(callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (source *mqttWeatherSource) newWeatherData(datapoint storage.WeatherData) error {
|
func (source *mqttWeatherSource) newWeatherData(datapoint storage.WeatherData) {
|
||||||
return source.weatherSource.NewWeatherData(datapoint)
|
source.weatherSource.NewWeatherData(datapoint)
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,12 +13,8 @@ func (source *WeatherSourceBase) AddNewWeatherDataCallback(callback NewWeatherDa
|
||||||
}
|
}
|
||||||
|
|
||||||
//NewWeatherData executes all newWeatherDataCallbackFuncs for this datapoint
|
//NewWeatherData executes all newWeatherDataCallbackFuncs for this datapoint
|
||||||
func (source *WeatherSourceBase) NewWeatherData(datapoint storage.WeatherData) error {
|
func (source *WeatherSourceBase) NewWeatherData(datapoint storage.WeatherData) {
|
||||||
for _, callback := range source.newWeatherDataCallbackFuncs {
|
for _, callback := range source.newWeatherDataCallbackFuncs {
|
||||||
err := callback(datapoint)
|
callback(datapoint)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package weathersource
|
||||||
import "weather-data/storage"
|
import "weather-data/storage"
|
||||||
|
|
||||||
//NewWeatherDataCallbackFunc Function-Signature for new weather data callback function
|
//NewWeatherDataCallbackFunc Function-Signature for new weather data callback function
|
||||||
type NewWeatherDataCallbackFunc func(storage.WeatherData) error
|
type NewWeatherDataCallbackFunc func(storage.WeatherData)
|
||||||
|
|
||||||
//WeatherSource is the interface for different weather-source implementations
|
//WeatherSource is the interface for different weather-source implementations
|
||||||
type WeatherSource interface {
|
type WeatherSource interface {
|
||||||
|
|
Loading…
Add table
Reference in a new issue