-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmeta.go
55 lines (47 loc) · 1.15 KB
/
meta.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
package spry
type ActorMeta struct {
// how many events should occur before the next snapshot
SnapshotFrequency int
// controls whether snapshots occur during fetch (read)
SnapshotDuringRead bool
// controls whether snapshots occur during handle (write)
SnapshotDuringWrite bool
// controls whether snapshots can occur during partitions
// requires a storage adapter for a database that can
// detect this
SnapshotDuringPartition bool
}
type HasMeta interface {
GetActorMeta() ActorMeta
}
var default_meta = ActorMeta{
SnapshotFrequency: 20,
SnapshotDuringRead: false,
SnapshotDuringWrite: true,
SnapshotDuringPartition: true,
}
func GetActorMeta[T any]() ActorMeta {
var empty any = getEmpty[T]()
hasMeta, ok := empty.(HasMeta)
if ok {
return hasMeta.GetActorMeta()
}
return default_meta
}
type EventMetadata struct {
CreatedBy string
CreatedFor string
}
func (e EventMetadata) GetEventMeta() EventMetadata {
return e
}
func GetEventMeta(event any) EventMetadata {
hasMeta, ok := event.(Namespaced)
if ok {
return hasMeta.GetEventMeta()
}
return EventMetadata{}
}
type Namespaced interface {
GetEventMeta() EventMetadata
}