diff --git a/api/rest-api.go b/api/rest-api.go index a2186fd..874696e 100644 --- a/api/rest-api.go +++ b/api/rest-api.go @@ -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) } diff --git a/main.go b/main.go index 8f03230..07920a7 100644 --- a/main.go +++ b/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 } diff --git a/weathersource/mqtt-source.go b/weathersource/mqtt-source.go index 4e9a7cc..8ed79a6 100644 --- a/weathersource/mqtt-source.go +++ b/weathersource/mqtt-source.go @@ -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) } diff --git a/weathersource/weather-source-base.go b/weathersource/weather-source-base.go index 86559f9..347b8b4 100644 --- a/weathersource/weather-source-base.go +++ b/weathersource/weather-source-base.go @@ -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 } diff --git a/weathersource/weather-source.go b/weathersource/weather-source.go index bc60d19..8930434 100644 --- a/weathersource/weather-source.go +++ b/weathersource/weather-source.go @@ -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 {