-
Notifications
You must be signed in to change notification settings - Fork 20
/
topic.go
60 lines (48 loc) · 1.32 KB
/
topic.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
package assets
import (
"fmt"
"github.com/nyaruka/gocommon/uuids"
)
// TopicUUID is the UUID of a topic
type TopicUUID uuids.UUID
// Topic categorizes tickets
//
// {
// "uuid": "cd48bd11-08b9-44e3-9778-8e26adf08a7a",
// "name": "Weather"
// }
//
// @asset topic
type Topic interface {
UUID() TopicUUID
Name() string
}
// TopicReference is used to reference a topic
type TopicReference struct {
UUID TopicUUID `json:"uuid" validate:"required,uuid"`
Name string `json:"name"`
}
// NewTopicReference creates a new topic reference with the given UUID and name
func NewTopicReference(uuid TopicUUID, name string) *TopicReference {
return &TopicReference{UUID: uuid, Name: name}
}
// Type returns the name of the asset type
func (r *TopicReference) Type() string {
return "topic"
}
// GenericUUID returns the untyped UUID
func (r *TopicReference) GenericUUID() uuids.UUID {
return uuids.UUID(r.UUID)
}
// Identity returns the unique identity of the asset
func (r *TopicReference) Identity() string {
return string(r.UUID)
}
// Variable returns whether this a variable (vs concrete) reference
func (r *TopicReference) Variable() bool {
return false
}
func (r *TopicReference) String() string {
return fmt.Sprintf("%s[uuid=%s,name=%s]", r.Type(), r.Identity(), r.Name)
}
var _ UUIDReference = (*TopicReference)(nil)