namespace

package
v0.14.9 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2021 License: Apache-2.0 Imports: 6 Imported by: 3

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 added in v0.14.8

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) 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 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 added in v0.14.8

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