-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsource_ref.go
More file actions
58 lines (50 loc) · 1.47 KB
/
Copy pathsource_ref.go
File metadata and controls
58 lines (50 loc) · 1.47 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
58
package contexty
// SourceRef points from semantic context nodes to host-owned source identity.
type SourceRef struct {
Namespace string `json:"namespace,omitempty"`
Kind string `json:"kind,omitempty"`
ID string `json:"id,omitempty"`
CheckpointID string `json:"checkpoint_id,omitempty"`
URI string `json:"uri,omitempty"`
}
func cloneSourceRefs(refs []SourceRef) []SourceRef {
if len(refs) == 0 {
return nil
}
out := make([]SourceRef, len(refs))
copy(out, refs)
return out
}
func cloneSourceRefPtr(ref *SourceRef) *SourceRef {
if ref == nil {
return nil
}
cp := *ref
return &cp
}
// Actor identifies the participant behind a provider-facing role.
type Actor struct {
Kind string `json:"kind,omitempty"`
ID string `json:"id,omitempty"`
DisplayName string `json:"display_name,omitempty"`
SourceRefs []SourceRef `json:"source_refs,omitempty"`
}
// Clone returns a deep copy.
func (a *Actor) Clone() *Actor {
if a == nil {
return nil
}
cp := *a
cp.SourceRefs = cloneSourceRefs(a.SourceRefs)
return &cp
}
// RoleProjectionPolicy maps actor-aware messages to provider-facing roles.
type RoleProjectionPolicy interface {
ProjectRole(Message) (Role, error)
}
// RoleProjectionFunc adapts a function to RoleProjectionPolicy.
type RoleProjectionFunc func(Message) (Role, error)
// ProjectRole implements RoleProjectionPolicy.
func (f RoleProjectionFunc) ProjectRole(msg Message) (Role, error) {
return f(msg)
}