-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
utils.go
48 lines (42 loc) · 1.14 KB
/
utils.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
package events
import (
"time"
commands "github.com/plgd-dev/hub/v2/resource-aggregate/commands"
)
// MakeEventMeta for creating EventMetadata for event.
func MakeEventMeta(connectionID string, sequence, version uint64) *EventMetadata {
return &EventMetadata{
ConnectionId: connectionID,
Sequence: sequence,
Version: version,
Timestamp: time.Now().UnixNano(),
}
}
func EqualResource(x, y *commands.Resource) bool {
return x.DeviceId == y.DeviceId &&
EqualStringSlice(x.ResourceTypes, y.ResourceTypes) &&
EqualStringSlice(x.Interfaces, y.Interfaces) &&
x.Anchor == y.Anchor &&
x.Title == y.Title &&
EqualStringSlice(x.SupportedContentTypes, y.SupportedContentTypes) &&
x.ValidUntil == y.ValidUntil &&
((x.Policy == nil && y.Policy == nil) ||
(x.Policy != nil && y.Policy != nil && x.Policy.BitFlags == y.Policy.BitFlags))
}
func EqualStringSlice(x, y []string) bool {
if len(x) != len(y) {
return false
}
for i := range x {
if x[i] != y[i] {
return false
}
}
return true
}
func IsExpired(now time.Time, validUntil time.Time) bool {
if validUntil.IsZero() {
return false
}
return now.After(validUntil)
}