comparison calsync/notificationrouter/notificationrouter.go @ 66:629d9ad289fe

doc & refactor
author drewp@bigasterisk.com
date Fri, 06 Sep 2024 17:26:11 -0700
parents 8aee4f5c4bdd
children
comparison
equal deleted inserted replaced
65:329144c7e711 66:629d9ad289fe
1 package notificationrouter 1 package notificationrouter
2 2
3 // Holds the map of (random) watchIds and the sync functions for the affected calendars. 3 // Holds the map of (random) watchIds and the sync functions for the affected
4 // calendars. When google sends a notification, this object calls the right
5 // sync.
4 6
5 import ( 7 import (
6 "log" 8 "log"
7 "net/http" 9 "net/http"
8 "time" 10 "time"
32 34
33 func (nr *NotificationRouter) NotificationHandler(w http.ResponseWriter, r *http.Request) { 35 func (nr *NotificationRouter) NotificationHandler(w http.ResponseWriter, r *http.Request) {
34 watchId := r.Header.Get("X-Goog-Channel-ID") 36 watchId := r.Header.Get("X-Goog-Channel-ID")
35 if nr.handlers[watchId] == nil { 37 if nr.handlers[watchId] == nil {
36 log.Println("incoming notification for unknown watch id", watchId, "(ignoring)") 38 log.Println("incoming notification for unknown watch id", watchId, "(ignoring)")
37 } else { 39 return
38 // todo: The first notification on a given watchId is the confirmation,
39 // and the sync func is probably (surely?) not needed.
40 log.Println("incoming notification for known watch id", watchId)
41 nr.handlers[watchId]()
42 } 40 }
41 // todo: The first notification on a given watchId is the confirmation,
42 // and the sync func is probably (surely?) not needed.
43 log.Println("incoming notification for known watch id", watchId)
44 nr.handlers[watchId]()
43 } 45 }
44 46
45 func NewWatchId() string { 47 func NewWatchId() string {
46 return uniuri.New() + "_" + time.Now().Format("15_04_05") 48 return uniuri.New() + "_" + time.Now().Format("15_04_05")
47 } 49 }