Documentation ¶
Index ¶
- Constants
- func FromContext(ctx context.Context) string
- func NewContext(ctx context.Context, namespace string) context.Context
- type Error
- type EventStore
- type Outbox
- func (o *Outbox) AddHandler(ctx context.Context, m eh.EventMatcher, h eh.EventHandler) error
- func (o *Outbox) Close() error
- func (o *Outbox) Errors() <-chan error
- func (o *Outbox) HandleEvent(ctx context.Context, event eh.Event) error
- func (o *Outbox) HandlerType() eh.EventHandlerType
- func (o *Outbox) PreRegisterNamespace(ns string) error
- func (o *Outbox) Start()
- type Repo
- func (r *Repo) Close() error
- func (r *Repo) Find(ctx context.Context, id uuid.UUID) (eh.Entity, error)
- func (r *Repo) FindAll(ctx context.Context) ([]eh.Entity, error)
- func (r *Repo) InnerRepo(ctx context.Context) eh.ReadRepo
- func (r *Repo) Remove(ctx context.Context, id uuid.UUID) error
- func (r *Repo) Save(ctx context.Context, entity eh.Entity) error
Constants ¶
const DefaultNamespace = "default"
DefaultNamespace is the namespace to use if not set in the context.
Variables ¶
This section is empty.
Functions ¶
func FromContext ¶
FromContext returns the namespace from the context, or the default namespace.
Types ¶
type Error ¶
type Error struct { // Err is the error. Err error // Namespace is the namespace for the error. Namespace string }
Error is an error that contains info about in which name space the underlying error occurred.
type EventStore ¶
type EventStore struct {
// contains filtered or unexported fields
}
EventStore is an event store with support for namespaces passed in the context.
func NewEventStore ¶
func NewEventStore(factory func(ns string) (eh.EventStore, error)) *EventStore
NewEventStore creates a new event store which will use the provided factory function to create new event stores for the provided namespace.
Usage:
eventStore := NewEventStore(func(ns string) (eh.EventStore, error) { s, err := mongodb.NewEventStore("mongodb://", ns) if err != nil { return nil, err } return s, nil })
Usage shared DB client:
client, err := mongo.Connect(ctx) ... eventStore := NewEventStore(func(ns string) (eh.EventStore, error) { s, err := mongodb.NewEventStoreWithClient(client, ns) if err != nil { return nil, err } return s, nil })
func (*EventStore) Close ¶
func (s *EventStore) Close() error
Close implements the Close method of the eventhorizon.EventStore interface.
func (*EventStore) PreRegisterNamespace ¶
func (s *EventStore) PreRegisterNamespace(ns string) error
PreRegisterNamespace will make sure that a namespace exists in the eventstore. In normal cases the eventstore for a namespace is created when an event for that namespace is first seen.
type Outbox ¶
type Outbox struct {
// contains filtered or unexported fields
}
Outbox is an outbox with support for namespaces passed in the context.
func NewOutbox ¶
NewOutbox creates a new outbox which will use the provided factory function to create new outboxes for the provided namespace.
Usage:
outbox := NewOutbox(func(ns string) (eh.Outbox, error) { s, err := mongodb.NewOutbox("mongodb://", ns) if err != nil { return nil, err } return s, nil })
Usage shared DB client:
client, err := mongo.Connect(ctx) ... outbox := NewOutbox(func(ns string) (eh.Outbox, error) { s, err := mongodb.NewOutboxWithClient(client, ns) if err != nil { return nil, err } return s, nil })
func (*Outbox) AddHandler ¶
func (o *Outbox) AddHandler(ctx context.Context, m eh.EventMatcher, h eh.EventHandler) error
AddHandler implements the AddHandler method of the eventhorizon.Outbox interface.
func (*Outbox) HandleEvent ¶
HandleEvent implements the HandleEvent method of the eventhorizon.Outbox interface.
func (*Outbox) HandlerType ¶
func (o *Outbox) HandlerType() eh.EventHandlerType
HandlerType implements the HandlerType method of the eventhorizon.EventHandler interface.
func (*Outbox) PreRegisterNamespace ¶
PreRegisterNamespace will make sure that a namespace exists in the outbox and that processing of that namespace is active. In normal cases the outbox for a namespace is started when an event for that namespace is first seen.
type Repo ¶
type Repo struct {
// contains filtered or unexported fields
}
Repo is a repo with support for namespaces passed in the context.
func IntoRepo ¶
IntoRepo tries to convert a eh.ReadRepo into a Repo by recursively looking at inner repos. Returns nil if none was found.
func NewRepo ¶
func NewRepo(factory func(ns string) (eh.ReadWriteRepo, error)) *Repo
NewRepo creates a new repo which will use the provided factory function to create new repos for the provided namespace.
Usage:
repo := NewRepo(func(ns string) (eh.ReadWriteRepo, error) { r, err := mongodb.NewRepo("mongodb://", "db", "model") if err != nil { return nil, err } r.SetEntityFactory(func() eh.Entity{ return &Model{} }) return r, nil })
Usage shared DB client:
client, err := mongo.Connect(ctx) ... repo := NewRepo(func(ns string) (eh.ReadWriteRepo, error) { r, err := mongodb.NewRepoWithClient(client, "db", "model") if err != nil { return nil, err } r.SetEntityFactory(func() eh.Entity{ return &Model{} }) return r, nil })
func (*Repo) FindAll ¶
FindAll implements the FindAll method of the eventhorizon.ReadRepo interface.
func (*Repo) InnerRepo ¶
InnerRepo implements the InnerRepo method of the eventhorizon.ReadRepo interface.