From 9f774c4a2195bce104e0a313883bf722c6de4085 Mon Sep 17 00:00:00 2001 From: Nils Date: Wed, 27 Aug 2025 10:58:14 +0200 Subject: [PATCH] Fix: Error return value of `w.Write` is not checked --- main.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 56d5db4..a25c196 100644 --- a/main.go +++ b/main.go @@ -149,13 +149,17 @@ func main() { // serveHome serves the main HTML page. func serveHome(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html") - w.Write(indexHTML) + if _, err := w.Write(indexHTML); err != nil { + log.Printf("Could not write response: %v", err) + } } // getMapSources serves the available map sources as JSON. func getMapSources(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") - w.Write(mapSourcesJSON) + if _, err := w.Write(mapSourcesJSON); err != nil { + log.Printf("Could not write response: %v", err) + } } // wsHandler handles WebSocket connections. @@ -703,7 +707,9 @@ func getCachedTiles(w http.ResponseWriter, r *http.Request) { } w.Header().Set("Content-Type", "application/json") - json.NewEncoder(w).Encode(cachedTiles) + if err := json.NewEncoder(w).Encode(cachedTiles); err != nil { + http.Error(w, fmt.Sprintf("Error encoding cached tiles: %v", err), http.StatusInternalServerError) + } } // getStyleName returns the name of the map style for a given URL.