From 3f9734598b6390ef3743f0eb10bc92cdae62ce49 Mon Sep 17 00:00:00 2001 From: Joel Schmid Date: Fri, 5 Mar 2021 23:40:20 +0100 Subject: [PATCH] only allow POST-method for addDataHandler --- api/rest-api.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/api/rest-api.go b/api/rest-api.go index 9e2329a..f25435b 100644 --- a/api/rest-api.go +++ b/api/rest-api.go @@ -40,7 +40,6 @@ func (api *weatherRestApi) handleRequests() *mux.Router { router.HandleFunc("/random", api.randomWeatherHandler) router.HandleFunc("/randomlist", api.randomWeatherListHandler) router.HandleFunc("/addData", api.addDataHandler) - return router } @@ -62,6 +61,10 @@ func (api *weatherRestApi) randomWeatherListHandler(w http.ResponseWriter, r *ht } func (api *weatherRestApi) addDataHandler(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + http.Error(w, "only POST-Method allowed", http.StatusMethodNotAllowed) + } + var data storage.WeatherData err := json.NewDecoder(r.Body).Decode(&data) if err != nil {