-
Notifications
You must be signed in to change notification settings - Fork 0
/
change.go
63 lines (59 loc) · 1.44 KB
/
change.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
58
59
60
61
62
63
package driveapicollector
import (
"fmt"
"github.com/scjalliance/drivestream/resource"
drive "google.golang.org/api/drive/v3"
)
// MarshalChange marshals the given change as a resource.
func MarshalChange(change *drive.Change) (resource.Change, error) {
changed, err := parseRFC3339(change.Time)
if err != nil {
return resource.Change{}, fmt.Errorf("invalid change time: %v", err)
}
switch change.Type {
case "file":
if change.File == nil {
return resource.Change{
Type: resource.TypeFile,
Time: changed,
Removed: change.Removed,
File: resource.File{
ID: resource.ID(change.FileId),
},
}, nil
}
record, err := MarshalFile(change.File)
if err != nil {
return resource.Change{}, err
}
return resource.Change{
Type: resource.TypeFile,
Time: changed,
Removed: change.Removed,
File: record,
}, nil
case "teamDrive":
if change.TeamDrive == nil {
return resource.Change{
Type: resource.TypeDrive,
Time: changed,
Removed: change.Removed,
Drive: resource.Drive{
ID: resource.ID(change.TeamDriveId),
},
}, nil
}
record, err := MarshalDrive(change.TeamDrive)
if err != nil {
return resource.Change{}, err
}
return resource.Change{
Type: resource.TypeDrive,
Time: changed,
Removed: change.Removed,
Drive: record,
}, nil
default:
return resource.Change{}, fmt.Errorf("unknown change type: \"%s\"", change.Type)
}
}