Mercurial > code > home > repos > gcalendarwatch
view calsync/mongoclient/mongoclient.go @ 50:dade5bbd02e3
refactor
author | drewp@bigasterisk.com |
---|---|
date | Mon, 19 Aug 2024 13:37:05 -0700 |
parents | 2991c1166852 |
children | a9b720445bcf |
line wrap: on
line source
package mongoclient import ( "context" "log" "time" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" ) type MongoClient struct { ctx context.Context client *mongo.Client db *mongo.Database calsCollection *mongo.Collection eventsCollection *mongo.Collection } // docs in eventsCollection type MongoEvent struct { // e.g. // { // "_id" : "http://bigasterisk.com/calendar/08s5m1_20140929T030000Z", // "htmlLink" : "https://www.google.com/calendar/event?eid=MDhz", // "title" : "meeting", // "feedId" : "drewpca@gmail.com", // "feedTitle" : "drewpca@gmail.com", // "endTimeUnspecified" : false, // "start" : "2014-09-28T20:00:00-07:00", // "startDate" : "2014-09-28", // "startTime" : ISODate("2014-09-29T03:00:00Z"), // "end" : "2014-09-28T21:00:00-07:00", // "endDate" : "2014-09-28", // "endTime" : ISODate("2014-09-29T04:00:00Z") // } Url string `bson:"_id"` GoogleId string `bson:"googleId"` HtmlLink string `bson:"htmlLink"` Title string `bson:"title"` FeedId string `bson:"feedId"` FeedTitle string `bson:"feedTitle"` EndTimeUnspecified bool `bson:"endTimeUnspecified"` Start string `bson:"start"` StartDate string `bson:"startDate"` StartTime time.Time `bson:"startTime"` End string `bson:"end"` EndDate string `bson:"endDate"` EndTime time.Time `bson:"endTime"` LastUpdated time.Time `bson:"lastUpdated"` } func New(ctx context.Context) (*MongoClient, error) { log.Println("todo: using fixed ip") mclient, err := mongo.Connect(ctx, options.Client().ApplyURI("mongodb://10.43.98.221:27017")) if err != nil { return nil, err } db := mclient.Database("pim") return &MongoClient{ ctx, mclient, db, db.Collection("test_gcalendar_cals"), db.Collection("test_gcalendar")}, nil } func (c *MongoClient) Close() { c.client.Disconnect(c.ctx) }