add logging

This commit is contained in:
Simon Rieger 2025-07-01 20:29:31 +02:00
parent ca377f660b
commit 9bbb9157fe

15
main.go
View file

@ -42,8 +42,17 @@ type NtfyMessage struct {
} }
func main() { func main() {
log.SetFlags(log.LstdFlags | log.Lmicroseconds | log.Lshortfile)
log.Println("Starte GoToSocial-Notifier...")
if pollInterval == 0 { if pollInterval == 0 {
pollInterval = 30 * time.Second pollInterval = 30 * time.Second
log.Printf("Kein POLL_INTERVAL gesetzt, verwende Default: %s", pollInterval)
}
if gotosocialURL == "" || accessToken == "" || ntfyServer == "" || ntfyTopic == "" {
log.Fatal("Eine oder mehrere erforderliche Umgebungsvariablen fehlen (GOTOSOCIAL_URL, GOTOSOCIAL_TOKEN, NTFY_SERVER, NTFY_TOPIC)")
} }
ticker := time.NewTicker(pollInterval) ticker := time.NewTicker(pollInterval)
@ -54,6 +63,7 @@ func main() {
for { for {
select { select {
case <-ticker.C: case <-ticker.C:
log.Println("Frage GoToSocial-Benachrichtigungen ab ...")
notifications, err := fetchNotifications(lastID) notifications, err := fetchNotifications(lastID)
if err != nil { if err != nil {
log.Printf("Fehler beim Abrufen: %v", err) log.Printf("Fehler beim Abrufen: %v", err)
@ -62,11 +72,16 @@ func main() {
if len(notifications) > 0 { if len(notifications) > 0 {
lastID = notifications[0].ID lastID = notifications[0].ID
log.Printf("%d neue Benachrichtigungen gefunden.", len(notifications))
} else {
log.Println("Keine neuen Benachrichtigungen.")
} }
for _, n := range notifications { for _, n := range notifications {
if err := sendToNtfy(n); err != nil { if err := sendToNtfy(n); err != nil {
log.Printf("Fehler beim Senden an ntfy: %v", err) log.Printf("Fehler beim Senden an ntfy: %v", err)
} else {
log.Printf("Benachrichtigung '%s' an ntfy gesendet.", n.ID)
} }
} }
} }