-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathmapUploader.go
More file actions
57 lines (44 loc) · 1.27 KB
/
mapUploader.go
File metadata and controls
57 lines (44 loc) · 1.27 KB
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
/*
This file is responsible for handling uploading of parsed event data to MongoDB.
*/
package uploader
import (
"context"
"fmt"
"log"
"os"
"time"
"github.com/UTDNebula/nebula-api/api/schema"
"github.com/joho/godotenv"
)
// Note that this uploader assumes that the collection names match the names of these files, which they should.
// If the names of these collections ever change, the file names should be updated accordingly.
var mapFilesToUpload [1]string = [1]string{"mapLocations.json"}
// UploadMapLocations replaces the map locations collection with the generated map JSON.
func UploadMapLocations(inDir string) {
//Load env vars
if err := godotenv.Load(); err != nil {
log.Panic("Error loading .env file")
}
//Connect to mongo
client := connectDB()
// Get 5 minute context
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()
for _, path := range mapFilesToUpload {
// Open data file for reading
fptr, err := os.Open(fmt.Sprintf("%s/"+path, inDir))
if err != nil {
if os.IsNotExist(err) {
log.Printf("File not found. Skipping %s", path)
continue
}
log.Panic(err)
}
defer fptr.Close()
switch path {
case "mapLocations.json":
UploadData[schema.MapBuilding](client, ctx, fptr, true)
}
}
}