/
notification_topic_metadata.go
58 lines (49 loc) · 1.26 KB
/
notification_topic_metadata.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
package gcloudcx
import (
"encoding/json"
"github.com/gildas/go-errors"
)
// MetadataTopic describes a Topic about the channel itself
type MetadataTopic struct {
Name string
Message string
}
func init() {
notificationTopicRegistry.Add(MetadataTopic{})
}
// GetType returns the type of this topic
//
// implements core.TypeCarrier
func (topic MetadataTopic) GetType() string {
return "channel.metadata"
}
// GetTargets returns the targets of this topic
func (topic MetadataTopic) GetTargets() []Identifiable {
return nil
}
// With creates a new NotificationTopic with the given targets
func (topic MetadataTopic) With(targets ...Identifiable) NotificationTopic {
newTopic := topic
return newTopic
}
// String gets a string version
//
// implements fmt.Stringer
func (topic MetadataTopic) String() string {
return topic.GetType()
}
// UnmarshalJSON unmarshals JSON into this
func (topic *MetadataTopic) UnmarshalJSON(payload []byte) (err error) {
var inner struct {
TopicName string `json:"topicName"`
EventBody struct {
Message string `json:"message"`
} `json:"eventBody"`
}
if err = json.Unmarshal(payload, &inner); err != nil {
return errors.JSONUnmarshalError.Wrap(err)
}
topic.Name = inner.TopicName
topic.Message = inner.EventBody.Message
return
}