namespace

package
v0.15.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 13, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultNamespace = "default"

DefaultNamespace is the namespace to use if not set in the context.

Variables

This section is empty.

Functions

func FromContext

func FromContext(ctx context.Context) string

FromContext returns the namespace from the context, or the default namespace.

func NewContext

func NewContext(ctx context.Context, namespace string) context.Context

NewContext sets the namespace to use in the context. The namespace is used to determine which database to use, among other things.

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.

func (*Error) Cause

func (e *Error) Cause() error

Cause implements the github.com/pkg/errors Unwrap method.

func (*Error) Error

func (e *Error) Error() string

Error implements the Error method of the errors.Error interface.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap implements the errors.Unwrap method.

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) Load

func (s *EventStore) Load(ctx context.Context, id uuid.UUID) ([]eh.Event, error)

Load implements the Load 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.

func (*EventStore) Save

func (s *EventStore) Save(ctx context.Context, events []eh.Event, originalVersion int) error

Save implements the Save method of the eventhorizon.EventStore interface.

type Outbox

type Outbox struct {
	// contains filtered or unexported fields
}

Outbox is an outbox with support for namespaces passed in the context.

func NewOutbox

func NewOutbox(factory func(ns string) (eh.Outbox, error)) *Outbox

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) Close

func (o *Outbox) Close() error

Close implements the Close method of the eventhorizon.Outbox interface.

func (*Outbox) Errors

func (o *Outbox) Errors() <-chan error

Errors implements the Errors method of the eventhorizon.EventBus interface.

func (*Outbox) HandleEvent

func (o *Outbox) HandleEvent(ctx context.Context, event eh.Event) error

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

func (o *Outbox) PreRegisterNamespace(ns string) error

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.

func (*Outbox) Start

func (o *Outbox) Start()

Start implements the Start method of the eventhorizon.Outbox interface.

type Repo

type Repo struct {
	// contains filtered or unexported fields
}

Repo is a repo with support for namespaces passed in the context.

func IntoRepo

func IntoRepo(ctx context.Context, repo eh.ReadRepo) *Repo

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) Close

func (r *Repo) Close() error

Close implements the Close method of the eventhorizon.WriteRepo interface.

func (*Repo) Find

func (r *Repo) Find(ctx context.Context, id uuid.UUID) (eh.Entity, error)

Find implements the Find method of the eventhorizon.ReadRepo interface.

func (*Repo) FindAll

func (r *Repo) FindAll(ctx context.Context) ([]eh.Entity, error)

FindAll implements the FindAll method of the eventhorizon.ReadRepo interface.

func (*Repo) InnerRepo

func (r *Repo) InnerRepo(ctx context.Context) eh.ReadRepo

InnerRepo implements the InnerRepo method of the eventhorizon.ReadRepo interface.

func (*Repo) Remove

func (r *Repo) Remove(ctx context.Context, id uuid.UUID) error

Remove implements the Remove method of the eventhorizon.WriteRepo interface.

func (*Repo) Save

func (r *Repo) Save(ctx context.Context, entity eh.Entity) error

Save implements the Save method of the eventhorizon.WriteRepo interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL