add logging
This commit is contained in:
parent
4aa1d57094
commit
e9b138be62
1 changed files with 17 additions and 3 deletions
20
go/main.go
20
go/main.go
|
@ -1,7 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -13,18 +13,24 @@ func convertICStoRSS(w http.ResponseWriter, r *http.Request) {
|
||||||
// Lese die ICS-URL aus dem Query-Parameter
|
// Lese die ICS-URL aus dem Query-Parameter
|
||||||
icsURL := r.URL.Query().Get("ics")
|
icsURL := r.URL.Query().Get("ics")
|
||||||
if icsURL == "" {
|
if icsURL == "" {
|
||||||
|
log.Println("[ERROR] Missing 'ics' query parameter")
|
||||||
http.Error(w, "Missing 'ics' query parameter", http.StatusBadRequest)
|
http.Error(w, "Missing 'ics' query parameter", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Printf("[INFO] Fetching ICS file from URL: %s\n", icsURL)
|
||||||
|
|
||||||
// ICS-Datei herunterladen
|
// ICS-Datei herunterladen
|
||||||
resp, err := http.Get(icsURL)
|
resp, err := http.Get(icsURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Printf("[ERROR] Unable to fetch ICS file: %v\n", err)
|
||||||
http.Error(w, "Unable to fetch ICS file", http.StatusInternalServerError)
|
http.Error(w, "Unable to fetch ICS file", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
log.Println("[INFO] Parsing ICS file")
|
||||||
|
|
||||||
// ICS-Datei parsen
|
// ICS-Datei parsen
|
||||||
parser := gocal.NewParser(resp.Body)
|
parser := gocal.NewParser(resp.Body)
|
||||||
parser.Parse()
|
parser.Parse()
|
||||||
|
@ -48,19 +54,27 @@ func convertICStoRSS(w http.ResponseWriter, r *http.Request) {
|
||||||
feed.Items = append(feed.Items, item)
|
feed.Items = append(feed.Items, item)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Println("[INFO] Generating RSS feed")
|
||||||
|
|
||||||
// RSS als HTTP-Antwort senden
|
// RSS als HTTP-Antwort senden
|
||||||
rssData, err := feed.ToRss()
|
rssData, err := feed.ToRss()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Printf("[ERROR] Unable to generate RSS feed: %v\n", err)
|
||||||
http.Error(w, "Unable to generate RSS feed", http.StatusInternalServerError)
|
http.Error(w, "Unable to generate RSS feed", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/rss+xml")
|
w.Header().Set("Content-Type", "application/rss+xml")
|
||||||
w.Write([]byte(rssData))
|
w.Write([]byte(rssData))
|
||||||
|
|
||||||
|
log.Println("[INFO] RSS feed successfully generated and sent")
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
http.HandleFunc("/rss", convertICStoRSS)
|
http.HandleFunc("/rss", convertICStoRSS)
|
||||||
fmt.Println("Server is running at :8080")
|
log.Println("[INFO] Server is running at :8080")
|
||||||
http.ListenAndServe(":8080", nil)
|
|
||||||
|
if err := http.ListenAndServe(":8080", nil); err != nil {
|
||||||
|
log.Fatalf("[FATAL] Server failed to start: %v\n", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue