comparison calsync/main.go @ 60:3b0595c2bf03

logging and small refactors
author drewp@bigasterisk.com
date Fri, 06 Sep 2024 16:41:48 -0700
parents 1f8e66cb0108
children 8aee4f5c4bdd
comparison
equal deleted inserted replaced
59:1f8e66cb0108 60:3b0595c2bf03
26 "bigasterisk.com/go/gcalendarwatch/mongoclient" 26 "bigasterisk.com/go/gcalendarwatch/mongoclient"
27 "github.com/gorilla/mux" 27 "github.com/gorilla/mux"
28 ) 28 )
29 29
30 func main() { 30 func main() {
31 startLogging()
31 ctx := context.Background() 32 ctx := context.Background()
32 33
33 log.SetFlags(log.LstdFlags | log.Lshortfile)
34 gc, err := gcalclient.New(ctx) 34 gc, err := gcalclient.New(ctx)
35 if err != nil { 35 if err != nil {
36 log.Fatal(err) 36 log.Fatal(err)
37 } 37 }
38 defer gc.Close() 38 defer gc.Close()
41 if err != nil { 41 if err != nil {
42 log.Fatal(err) 42 log.Fatal(err)
43 } 43 }
44 defer mc.Close() 44 defer mc.Close()
45 45
46 // todo: if a cal is deleted, nothing touches its db events ever again. 46 // todo: if a cal is deleted, we don't clean up its events, even upon
47 // restart.
47 err = updateMongoCalsToMatchGoogleOnce(mc, gc) 48 err = updateMongoCalsToMatchGoogleOnce(mc, gc)
48 if err != nil { 49 if err != nil {
49 log.Fatal(err) 50 log.Fatal(err)
50 } 51 }
51 52
66 addr:=":8080" 67 addr:=":8080"
67 log.Println("serving /gcalendarwatch/notifications on", addr) 68 log.Println("serving /gcalendarwatch/notifications on", addr)
68 log.Fatal(http.ListenAndServe(addr, nil)) 69 log.Fatal(http.ListenAndServe(addr, nil))
69 } 70 }
70 71
72 func startLogging() {
73 log.SetFlags(log.LstdFlags | log.Lshortfile)
74 log.Println(`
75 ==================================================
76 calsync
77 ----------------------------------------------`)
71 } 78 }
72 79
73 func homePage(w http.ResponseWriter, r *http.Request) { 80 func homePage(w http.ResponseWriter, r *http.Request) {
74 w.Write([]byte("calsync service for calendar updates. See https://console.cloud.google.com/apis/api/calendar-json.googleapis.com/metrics?project=bigasterisk-910")) 81 w.Write([]byte("calsync service for calendar updates. See https://console.cloud.google.com/apis/api/calendar-json.googleapis.com/metrics?project=bigasterisk-910"))
75 } 82 }