-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
57 lines (45 loc) · 1.26 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package covid19brazilimporter
import (
"context"
"time"
"cloud.google.com/go/firestore"
)
type properties struct {
Filename string
Repo string
RepoOwner string
Branch string
CommitMessage string
CommiterName string
CommiterEmail string
}
const projectID = "covid19-radar-276100"
func getProperties(ctx context.Context, firestoreClient *firestore.Client) (*properties, error) {
doc, getDocError := firestoreClient.Collection("Config").Doc("properties").Get(ctx)
if getDocError != nil {
return nil, getDocError
}
p := &properties{}
doc.DataTo(p)
return p, nil
}
func getLastUpdate(ctx context.Context, firestoreClient *firestore.Client) (*time.Time, error) {
doc, getDocError := firestoreClient.Collection("Config").Doc("lastUpdate").Get(ctx)
if getDocError != nil {
return nil, getDocError
}
possibleLastUpdate, found := doc.Data()["lastUpdate"]
var lastUpdate time.Time
if !found {
lastUpdate = time.Unix(0, 0)
} else {
lastUpdate = possibleLastUpdate.(time.Time)
}
return &lastUpdate, nil
}
func setLastUpdate(ctx context.Context, firestoreClient *firestore.Client) (err error) {
_, err = firestoreClient.Collection("Config").Doc("lastUpdate").Set(ctx, map[string]interface{}{
"lastUpdate": time.Now(),
})
return
}