Browse Source

:gear: Add marshalling accessor to Message

mudler 3 years ago
parent
commit
c01e83f9df
1 changed files with 10 additions and 0 deletions
  1. 10 0
      pkg/hub/message.go

+ 10 - 0
pkg/hub/message.go

@@ -15,6 +15,8 @@
 
 
 package hub
 package hub
 
 
+import "encoding/json"
+
 // Message gets converted to/from JSON and sent in the body of pubsub messages.
 // Message gets converted to/from JSON and sent in the body of pubsub messages.
 type Message struct {
 type Message struct {
 	Message  string
 	Message  string
@@ -53,3 +55,11 @@ func (m *Message) WithMessage(s string) *Message {
 	copy.Message = s
 	copy.Message = s
 	return copy
 	return copy
 }
 }
+
+func (m *Message) AnnotationsToObj(v interface{}) error {
+	blob, err := json.Marshal(m.Annotations)
+	if err != nil {
+		return err
+	}
+	return json.Unmarshal(blob, v)
+}