Skip to content

Commit

Permalink
Add commonly needed message getters (#179)
Browse files Browse the repository at this point in the history
What we've seen is a common usage pattern of having to build generic
functions around the usage of Change and Event messages. By adding some
commonly used functions to access data from the message, it facilitates
a better user experience when building a downstream interface to take
advantage of these fields.

---------

Signed-off-by: Tyler Auerbeck <[email protected]>
Co-authored-by: Tyler Auerbeck <[email protected]>
  • Loading branch information
tylerauerbeck and tylerauerbeck authored Jan 8, 2024
1 parent c7056ab commit 4fc0e32
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions events/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,36 @@ func (m ChangeMessage) GetTraceContext(ctx context.Context) context.Context {
return tp.Extract(ctx, propagation.MapCarrier(m.TraceContext))
}

// GetSubject returns the subject of the message
func (m ChangeMessage) GetSubject() gidx.PrefixedID {
return m.SubjectID
}

// GetSubject returns the subject of the message
func (m EventMessage) GetSubject() gidx.PrefixedID {
return m.SubjectID
}

// GetAddSubjects returns the additional subjects of the message
func (m ChangeMessage) GetAddSubjects() []gidx.PrefixedID {
return m.AdditionalSubjectIDs
}

// GetAddSubjects returns the additional subjects of the message
func (m EventMessage) GetAddSubjects() []gidx.PrefixedID {
return m.AdditionalSubjectIDs
}

// GetEventType returns the event type of the message
func (m ChangeMessage) GetEventType() string {
return m.EventType
}

// GetEventType returns the event type of the message
func (m EventMessage) GetEventType() string {
return m.EventType
}

// Validate ensures the message has all the required fields.
func (m ChangeMessage) Validate() error {
var err error
Expand Down

0 comments on commit 4fc0e32

Please sign in to comment.