From e9b138be62fc312d4ef542938e12198282236c4b Mon Sep 17 00:00:00 2001 From: Simon Rieger Date: Thu, 24 Oct 2024 12:54:47 +0200 Subject: [PATCH] add logging --- go/main.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/go/main.go b/go/main.go index 1c1ce55..0c4c24c 100644 --- a/go/main.go +++ b/go/main.go @@ -1,7 +1,7 @@ package main import ( - "fmt" + "log" "net/http" "time" @@ -13,18 +13,24 @@ func convertICStoRSS(w http.ResponseWriter, r *http.Request) { // Lese die ICS-URL aus dem Query-Parameter icsURL := r.URL.Query().Get("ics") if icsURL == "" { + log.Println("[ERROR] Missing 'ics' query parameter") http.Error(w, "Missing 'ics' query parameter", http.StatusBadRequest) return } + log.Printf("[INFO] Fetching ICS file from URL: %s\n", icsURL) + // ICS-Datei herunterladen resp, err := http.Get(icsURL) if err != nil { + log.Printf("[ERROR] Unable to fetch ICS file: %v\n", err) http.Error(w, "Unable to fetch ICS file", http.StatusInternalServerError) return } defer resp.Body.Close() + log.Println("[INFO] Parsing ICS file") + // ICS-Datei parsen parser := gocal.NewParser(resp.Body) parser.Parse() @@ -48,19 +54,27 @@ func convertICStoRSS(w http.ResponseWriter, r *http.Request) { feed.Items = append(feed.Items, item) } + log.Println("[INFO] Generating RSS feed") + // RSS als HTTP-Antwort senden rssData, err := feed.ToRss() if err != nil { + log.Printf("[ERROR] Unable to generate RSS feed: %v\n", err) http.Error(w, "Unable to generate RSS feed", http.StatusInternalServerError) return } w.Header().Set("Content-Type", "application/rss+xml") w.Write([]byte(rssData)) + + log.Println("[INFO] RSS feed successfully generated and sent") } func main() { http.HandleFunc("/rss", convertICStoRSS) - fmt.Println("Server is running at :8080") - http.ListenAndServe(":8080", nil) + log.Println("[INFO] Server is running at :8080") + + if err := http.ListenAndServe(":8080", nil); err != nil { + log.Fatalf("[FATAL] Server failed to start: %v\n", err) + } }