Mercurial > code > home > repos > gcalendarwatch
comparison calsync/main.go @ 57:24f662799710
WIP incremental sync now runs
author | drewp@bigasterisk.com |
---|---|
date | Thu, 05 Sep 2024 15:03:05 -0700 |
parents | 635ff76f867c |
children | 1f8e66cb0108 |
comparison
equal
deleted
inserted
replaced
56:635ff76f867c | 57:24f662799710 |
---|---|
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 _ = http.StripPrefix | |
32 _ = mux.NewRouter | |
33 | |
34 ctx := context.Background() | 31 ctx := context.Background() |
35 | 32 |
36 log.SetFlags(log.LstdFlags | log.Lshortfile) | 33 log.SetFlags(log.LstdFlags | log.Lshortfile) |
37 gc, err := gcalclient.New(ctx) | 34 gc, err := gcalclient.New(ctx) |
38 if err != nil { | 35 if err != nil { |
45 log.Fatal(err) | 42 log.Fatal(err) |
46 } | 43 } |
47 defer mc.Close() | 44 defer mc.Close() |
48 | 45 |
49 // todo: if a cal is deleted, nothing touches its db events ever again. | 46 // todo: if a cal is deleted, nothing touches its db events ever again. |
50 // err = updateMongoCalsToMatchGoogleOnce(mc, gc) | 47 err = updateMongoCalsToMatchGoogleOnce(mc, gc) |
51 // if err != nil { | 48 if err != nil { |
52 // log.Fatal(err) | 49 log.Fatal(err) |
53 // } | 50 } |
54 | 51 |
55 err = updateMongoEventsToMatchGoogleForever(mc, gc, | 52 err = updateMongoEventsToMatchGoogleForever(mc, gc, |
56 time.Duration(7*24)*time.Hour, | 53 time.Duration(7*24)*time.Hour, |
57 time.Duration(14*24)*time.Hour) | 54 time.Duration(14*24)*time.Hour) |
58 if err != nil { | 55 if err != nil { |
59 log.Fatal(err) | 56 log.Fatal(err) |
60 } | 57 } |
61 log.Fatal("err was nil: updateMongoEventsToMatchGoogleForever shouldn't have returned") | |
62 | 58 |
63 /* | 59 r := mux.NewRouter() |
64 ------------------ | 60 http.Handle("/", r) |
65 connect to mongodb with these ops: | |
66 save cals list | |
67 get/set incremental token | |
68 add/edit/del events | |
69 collection.find({"startTime": {"$gte": t1, "$lt": t2}}).sort([("startTime", 1)]) | |
70 collection.find({"startTime": {"$lte": now}, "endTime": {"$gte": now}})) | |
71 | 61 |
72 connect to https://github.com/googleapis/google-api-go-client/tree/main/calendar/v3 and: | 62 home := func(w http.ResponseWriter, r *http.Request) { |
73 get all my cals | 63 w.Write([]byte("calsync service for calendar updates")) |
64 } | |
65 r.HandleFunc("/", home) | |
66 r.HandleFunc("/gcalendarwatch", home) | |
74 | 67 |
75 subscribe to events | 68 notificationHandler := func(w http.ResponseWriter, r *http.Request) { |
76 | 69 } |
77 get cal event changes from incremental token | 70 r.HandleFunc("/gcalendarwatch/notification", notificationHandler).Methods("POST") |
78 | 71 log.Println(("serving /gcalendarwatch/notification on :8080")) |
79 get cal events in range, for initial fill? | 72 log.Fatal(http.ListenAndServe(":8080", nil)) |
80 | |
81 write add/edit/del changes to mongo | |
82 */ | |
83 | |
84 // r := mux.NewRouter() | |
85 // http.Handle("/", r) | |
86 | |
87 // home := func(w http.ResponseWriter, r *http.Request) { | |
88 // w.Write([]byte("calsync service for calendar updates")) | |
89 // } | |
90 // r.HandleFunc("/", home) | |
91 // r.HandleFunc("/gcalendarwatch", home) | |
92 | |
93 // notificationHandler := func(w http.ResponseWriter, r *http.Request) { | |
94 // } | |
95 // r.HandleFunc("/gcalendarwatch/notification", notificationHandler).Methods("POST") | |
96 // log.Println(("serving /gcalendarwatch/notification on :8080")) | |
97 // log.Fatal(http.ListenAndServe(":8080", nil)) | |
98 } | 73 } |