Documentation ¶
Index ¶
- Constants
- func Emit(es Stream, et EventType, payload interface{})
- func EmitWithContext(es Stream, et EventType, payload interface{}, eventContext Context)
- type Command
- type CommandType
- type Context
- type CorrelationID
- type Event
- type EventType
- type Header
- type ID
- type Identifier
- type Reply
- func (r *Reply) CommandType() CommandType
- func (r *Reply) Copy() *Reply
- func (r *Reply) CorrelationID() CorrelationID
- func (r *Reply) Err() error
- func (r *Reply) IsErrorType() bool
- func (r *Reply) IsSuccessType() bool
- func (r *Reply) Payload() interface{}
- func (r *Reply) StreamID() ID
- func (r *Reply) StreamType() Type
- func (r *Reply) Type() ReplyType
- func (r *Reply) Version() Version
- type ReplyType
- type Stream
- type Type
- type Version
- type Versioner
Constants ¶
const ( ErrorReplyType = ReplyType("Error") SuccessReplyType = ReplyType("Success") UnknownReplyType = ReplyType("Unknown") )
const ( EventTypeIDKey = "_eventType" StreamTypeIDKey = "_streamType" CorrelationIDKey = "_correlationID" ReplyToKey = "_replyTo" )
Variables ¶
This section is empty.
Functions ¶
func Emit ¶
Emit stores new events on the stream and then applies them to the stream with default context.
func EmitWithContext ¶
EmitWithContext stores new events on the stream and then applies them to the stream.
Types ¶
type Command ¶
type Command interface { // StreamID returns the id of the stream that the command relates to. StreamID() ID // StreamType returns the type of the stream that the command relates to. StreamType() Type // Type returns the command type. Type() CommandType // Payload returns the command payload. Payload() interface{} // Header returns the command headers. Header() Header // Reply constructs a new Reply with the payload and version. Reply(reply interface{}, v Version) *Reply // ReplyOkWithVersion constructs a new success Reply with the specified version. ReplyOkWithVersion(v Version) *Reply // ReplyWithError constructs a new error Reply with the specified error. ReplyWithError(err error) *Reply // ReplyOk constructs a new success Reply without the specified version. ReplyOk() *Reply // ReplyWith constructs a new Reply. ReplyWith(rt ReplyType, reply interface{}, v Version) *Reply }
Command represents the intention to change the state of the stream.
func NewCommand ¶
func NewCommand(st Type, sid ID, ct CommandType, payload interface{}) Command
NewCommand constructs a new Command.
type CommandType ¶
type CommandType string
func (CommandType) String ¶
func (t CommandType) String() string
type CorrelationID ¶
type CorrelationID string
func NewCorrelationID ¶
func NewCorrelationID() CorrelationID
func (CorrelationID) Equal ¶
func (cid CorrelationID) Equal(correlationID string) bool
func (CorrelationID) String ¶
func (cid CorrelationID) String() string
type Event ¶
type Event interface { // StreamID returns the id of the stream that the event relates to. StreamID() ID // SetStreamID sets the stream id. SetStreamID(id ID) // StreamType returns the type of the stream that the event relates to. StreamType() Type // Version returns the version of the event. Version() Version // Context returns the event context. Context() Context // Payload returns the event payload. Payload() interface{} // Type returns the event type. Type() EventType // CreatedAt returns the time when the event was created. CreatedAt() time.Time // Generation returns the payload semantic version. // Default 0. Generation() int // SetGeneration sets the semantic version for the payload. SetGeneration(int) }
Event represents something that took place in the domain. They are always named with a past-participle verb.
type Header ¶
func (Header) CorrelationID ¶
func (h Header) CorrelationID() CorrelationID
func (Header) SetCorrelationID ¶
func (h Header) SetCorrelationID(cid CorrelationID)
func (Header) SetReplyTo ¶
func (Header) ShouldReply ¶
type Identifier ¶
type Reply ¶
type Reply struct {
// contains filtered or unexported fields
}
Reply represents the reply to the command.
func NewReply ¶
func NewReply(cid CorrelationID, sid ID, st Type, rt ReplyType, ct CommandType, v Version, p interface{}, err error) *Reply
func (*Reply) CommandType ¶
func (r *Reply) CommandType() CommandType
func (*Reply) CorrelationID ¶
func (r *Reply) CorrelationID() CorrelationID
func (*Reply) IsErrorType ¶
func (*Reply) IsSuccessType ¶
func (*Reply) StreamType ¶
type Stream ¶
type Stream interface { // ID returns the ID. ID() ID // SetID sets the ID after rehydrate from store. SetID(ID) // Type returns the stream type. Type() Type // Version returns the version of the stream. Version() Version // PreviousVersion returns the version of the stream with no current changes. PreviousVersion() Version // IncrementVersion increments the stream version number by one. IncrementVersion() // Changes returns the list of new events. Changes() []Event // ClearChanges removes all new events from the stream. ClearChanges() // AddChange stores the new event in the stream. AddChange(Event) // Apply applies the new event in the stream. Apply(Event, bool) }
A stream represents a current state as a sequence of events. Stream can be viewed as a whole in terms of data modification. All calls to stream must be made through its root, which is an entity with a globally unique identifier stream.ID. All internal objects of the stream have only local identity, they can refer to each other in any way.