goengine: github.com/hellofresh/goengine Index | Files | Directories

package goengine

import "github.com/hellofresh/goengine"

Index

Package Files

errors.go eventstore.go logger.go logger_nop.go message.go message_payload.go projection.go

func IsUUIDEmpty Uses

func IsUUIDEmpty(id UUID) bool

IsUUIDEmpty returns true if the UUID is empty

type EventStore Uses

type EventStore interface {
    ReadOnlyEventStore

    // Create creates an event stream
    Create(ctx context.Context, streamName StreamName) error

    // AppendTo appends the provided messages to the stream
    AppendTo(ctx context.Context, streamName StreamName, streamEvents []Message) error
}

EventStore an interface describing an event store

type EventStream Uses

type EventStream interface {
    // Next prepares the next result for reading.
    // It returns true on success, or false if there is no next result row or an error happened while preparing it.
    // Err should be consulted to distinguish between the two cases.
    Next() bool

    // Err returns the error, if any, that was encountered during iteration.
    Err() error

    // Close closes the EventStream, preventing further enumeration. If Next is called
    // and returns false and there are no further result sets,
    // result of Err. Close is idempotent and does not affect the result of Err.
    Close() error

    // Message returns the current message and it's number within the EventStream.
    Message() (Message, int64, error)
}

EventStream is the result of an event store query. Its cursor starts before the first row of the result set. Use Next to advance through the results:

type Fields Uses

type Fields map[string]interface{}

Fields a map of context provided to the logger

type InvalidArgumentError Uses

type InvalidArgumentError string

InvalidArgumentError indicates that the caller is in error and passed an incorrect value.

func (InvalidArgumentError) Error Uses

func (i InvalidArgumentError) Error() string

type Logger Uses

type Logger interface {
    Error(msg string, fields func(LoggerEntry))
    Warn(msg string, fields func(LoggerEntry))
    Info(msg string, fields func(LoggerEntry))
    Debug(msg string, fields func(LoggerEntry))

    WithFields(fields func(LoggerEntry)) Logger
}

Logger a structured logger interface

var NopLogger Logger = &nopLogger{}

NopLogger is a no-op Logger. This logger is used when a logger with the value `nil` is passed and avoids the need for `if logger != nil` everywhere

type LoggerEntry Uses

type LoggerEntry interface {
    Int(k string, v int)
    Int64(s string, v int64)
    String(k, v string)
    Error(err error)
    Any(k string, v interface{})
}

LoggerEntry represents the entry to be logger. This entry can be enhanced with more date.

type Message Uses

type Message interface {
    // UUID returns the identifier of this message
    UUID() UUID

    // CreatedAt returns the created time of the message
    CreatedAt() time.Time

    // Payload returns the payload of the message
    Payload() interface{}

    // Metadata return the message metadata
    Metadata() metadata.Metadata

    // WithMetadata Returns new instance of the message with key and value added to metadata
    WithMetadata(key string, value interface{}) Message
}

Message is a interface describing a message. A message can be a command, domain event or some other type of message.

func ReadEventStream Uses

func ReadEventStream(stream EventStream) ([]Message, []int64, error)

ReadEventStream reads the entire event stream and returns it's content as a slice. The main purpose of the function is for testing and debugging.

type MessageHandler Uses

type MessageHandler func(ctx context.Context, state interface{}, message Message) (interface{}, error)

MessageHandler is a func that can do state changes based on a message

type MessagePayloadConverter Uses

type MessagePayloadConverter interface {
    // ConvertPayload generates unique name for the event_name
    ConvertPayload(payload interface{}) (name string, data []byte, err error)
}

MessagePayloadConverter an interface describing converting payload data

type MessagePayloadFactory Uses

type MessagePayloadFactory interface {
    // CreatePayload returns a reconstructed payload or a error
    CreatePayload(payloadType string, data interface{}) (interface{}, error)
}

MessagePayloadFactory is used to reconstruct message payloads

type MessagePayloadResolver Uses

type MessagePayloadResolver interface {
    // ResolveName resolves the name of the underlying payload type
    ResolveName(payload interface{}) (string, error)
}

MessagePayloadResolver is used resolve the event_name of a payload

type Projection Uses

type Projection interface {
    Query

    // Name returns the name of the projection
    Name() string

    // FromStream returns the stream this projection is based on
    FromStream() StreamName
}

Projection contains the information of a projection

type ProjectionSaga Uses

type ProjectionSaga interface {
    Projection

    // DecodeState reconstitute the projection state based on the provided state data
    DecodeState(data []byte) (interface{}, error)

    // EncodeState encode the given object for storage
    EncodeState(obj interface{}) ([]byte, error)
}

ProjectionSaga is a projection that contains state data

type Query Uses

type Query interface {
    // init initializes the state of the Query
    Init(ctx context.Context) (interface{}, error)

    // Handlers return the handlers for a set of messages
    Handlers() map[string]MessageHandler
}

Query contains the information of a query

Example when querying the total the amount of deposits the query could be as follows.

type TotalDepositState struct {
	deposited int
	times     int
}

type TotalDepositQuery struct {}
func (q *TotalDepositQuery) Init(ctx context.Context) (interface{}, error) {
	return TotalDepositState{}, nil
}
func (q *TotalDepositQuery) Handlers() interface{} {
	return map[string]MessageHandler{
		"deposited": func(ctx context.Context, state interface{}, message goengine.Message) (interface{}, error) {
			depositState := state.(TotalDepositState)

			switch event := message.Payload().(type) {
			case AccountDebited:
				depositState.deposited += event.Amount
			}

			return depositState, nil
		},
	}
}

type ReadOnlyEventStore Uses

type ReadOnlyEventStore interface {
    // HasStream returns true if the stream exists
    HasStream(ctx context.Context, streamName StreamName) bool

    // Load returns a list of events based on the provided conditions
    Load(ctx context.Context, streamName StreamName, fromNumber int64, count *uint, metadataMatcher metadata.Matcher) (EventStream, error)
}

ReadOnlyEventStore an interface describing a readonly event store

type StreamName Uses

type StreamName string

StreamName is the name of an event stream

type UUID Uses

type UUID = uuid.UUID

UUID is a 128 bit (16 byte) Universal Unique IDentifier as defined in RFC4122

func GenerateUUID Uses

func GenerateUUID() UUID

GenerateUUID creates a new random UUID or panics

Directories

PathSynopsis
aggregate
driver/generic
driver/inmemoryCode generated by goengine.
driver/sql
driver/sql/internal
driver/sql/postgres
extension/logrus
extension/pq
extension/zap
internal/mocksPackage mocks is only used to test the reflection name of the type.
internal/mocks/payload
internal/reflect
metadata
mocksCode generated by mockery v1.0.0.
strategy/json
strategy/json/sql
strategy/json/sql/postgres

Package goengine imports 4 packages (graph) and is imported by 16 packages. Updated 2019-03-12. Refresh now. Tools for package owners.