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
|
||||
}
|
||||
|
||||
err = api.addNewWeatherData(*weatherData)
|
||||
if err != nil {
|
||||
http.Error(w, "", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
api.addNewWeatherData(*weatherData)
|
||||
|
||||
w.Header().Add("content-type", "application/json")
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
|
@ -336,6 +332,6 @@ func (api *weatherRestApi) AddNewWeatherDataCallback(callback weathersource.NewW
|
|||
api.weatherSource.AddNewWeatherDataCallback(callback)
|
||||
}
|
||||
|
||||
func (api *weatherRestApi) addNewWeatherData(weatherData storage.WeatherData) error {
|
||||
return api.weatherSource.NewWeatherData(weatherData)
|
||||
func (api *weatherRestApi) addNewWeatherData(weatherData storage.WeatherData) {
|
||||
api.weatherSource.NewWeatherData(weatherData)
|
||||
}
|
||||
|
|
10
main.go
10
main.go
|
@ -1,7 +1,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"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)
|
||||
if !config.AllowUnregisteredSensors && err != nil {
|
||||
log.Print("discarded invalid weatherdata")
|
||||
return fmt.Errorf("could not resolve sensor")
|
||||
if config.AllowUnregisteredSensors || err == nil {
|
||||
weatherStorage.Save(wd)
|
||||
}
|
||||
weatherStorage.Save(wd)
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -135,6 +135,6 @@ func (source *mqttWeatherSource) AddNewWeatherDataCallback(callback NewWeatherDa
|
|||
source.weatherSource.AddNewWeatherDataCallback(callback)
|
||||
}
|
||||
|
||||
func (source *mqttWeatherSource) newWeatherData(datapoint storage.WeatherData) error {
|
||||
return source.weatherSource.NewWeatherData(datapoint)
|
||||
func (source *mqttWeatherSource) newWeatherData(datapoint storage.WeatherData) {
|
||||
source.weatherSource.NewWeatherData(datapoint)
|
||||
}
|
||||
|
|
|
@ -13,12 +13,8 @@ func (source *WeatherSourceBase) AddNewWeatherDataCallback(callback NewWeatherDa
|
|||
}
|
||||
|
||||
//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 {
|
||||
err := callback(datapoint)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
callback(datapoint)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package weathersource
|
|||
import "weather-data/storage"
|
||||
|
||||
//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
|
||||
type WeatherSource interface {
|
||||
|
|
Loading…
Add table
Reference in a new issue