/
marshaler.go
25 lines (20 loc) · 990 Bytes
/
marshaler.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
package cqrs
import (
"github.com/ThreeDotsLabs/watermill/message"
)
// CommandEventMarshaler marshals Commands and Events to Watermill's messages and vice versa.
// Payload of the command needs to be marshaled to []bytes.
type CommandEventMarshaler interface {
// Marshal marshals Command or Event to Watermill's message.
Marshal(v interface{}) (*message.Message, error)
// Unmarshal unmarshals watermill's message to v Command or Event.
Unmarshal(msg *message.Message, v interface{}) (err error)
// Name returns the name of Command or Event.
// Name is used to determine, that received command or event is event which we want to handle.
Name(v interface{}) string
// NameFromMessage returns the name of Command or Event from Watermill's message (generated by Marshal).
//
// When we have Command or Event marshaled to Watermill's message,
// we should use NameFromMessage instead of Name to avoid unnecessary unmarshaling.
NameFromMessage(msg *message.Message) string
}