memory

package
v0.120.1 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2023 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	CreateEvent     = `Create`
	UpdateEvent     = `Update`
	DeleteAllEvent  = `DeleteAll`
	DeleteByIDEvent = `DeleteByID`
)

Name Types

Variables

This section is empty.

Functions

func LogHistoryOnFailure

func LogHistoryOnFailure(tb testingTB, el EventViewer)

func MakeID added in v0.93.0

func MakeID[ID any](context.Context) (ID, error)

func RewriteEventLog

func RewriteEventLog[EventType any](el *EventLog, rewrite func(es []EventType) []EventType)

Types

type Event

type Event = interface{}

type EventLog

type EventLog struct {
	Options struct {
		DisableAsyncSubscriptionHandling bool
	}
	// contains filtered or unexported fields
}

EventLog is an event source principles based in memory resource, that allows easy debugging and tracing during development for fast and descriptive feedback loops.

func NewEventLog

func NewEventLog() *EventLog

func (*EventLog) Append

func (el *EventLog) Append(ctx context.Context, event Event) error

func (*EventLog) Atomic

func (el *EventLog) Atomic(ctx context.Context, fn func(tx *EventLogTx) error) error

func (*EventLog) BeginTx

func (el *EventLog) BeginTx(ctx context.Context) (context.Context, error)

func (*EventLog) CommitTx

func (el *EventLog) CommitTx(ctx context.Context) error

func (*EventLog) Compress

func (el *EventLog) Compress()

func (*EventLog) Events

func (el *EventLog) Events() []Event

func (*EventLog) EventsInContext

func (el *EventLog) EventsInContext(ctx context.Context) []Event

func (*EventLog) LookupMeta

func (el *EventLog) LookupMeta(ctx context.Context, key string, ptr interface{}) (_found bool, _err error)

func (*EventLog) LookupTx

func (el *EventLog) LookupTx(ctx context.Context) (*EventLogTx, bool)

func (*EventLog) Rewrite

func (el *EventLog) Rewrite(mapper func(es []Event) []Event)

func (*EventLog) RollbackTx

func (el *EventLog) RollbackTx(ctx context.Context) error

func (*EventLog) SetMeta

func (el *EventLog) SetMeta(ctx context.Context, key string, value interface{}) (context.Context, error)

func (*EventLog) Subscribe

func (el *EventLog) Subscribe(ctx context.Context, subscriber EventLogSubscriber) (pubsub.Subscription, error)

type EventLogEvent

type EventLogEvent struct {
	Type  string
	Name  string
	Trace []Stack
}

func (EventLogEvent) GetTrace

func (et EventLogEvent) GetTrace() []Stack

func (EventLogEvent) SetTrace

func (et EventLogEvent) SetTrace(trace []Stack)

func (EventLogEvent) String

func (et EventLogEvent) String() string

type EventLogRepository added in v0.82.0

type EventLogRepository[Entity, ID any] struct {
	EventLog *EventLog
	MakeID   func(ctx context.Context) (ID, error)

	// Namespace separates different repository events in the event log.
	// By default same entities reside under the same Namespace through their fully qualified name used as namespace ID.
	// If you want create multiple EventLogRepository that works with the same entity but act as separate repositories,
	// you need to assign a unique Namespace for each of these EventLogRepository.
	Namespace string

	Options struct {
		CompressEventLog bool
	}
	// contains filtered or unexported fields
}

EventLogRepository is an EventLog based development in memory repository, that allows easy debugging and tracing during development for fast and descriptive feedback loops.

func NewEventLogRepository added in v0.82.0

func NewEventLogRepository[Entity, ID any](m *EventLog) *EventLogRepository[Entity, ID]

func NewEventLogRepositoryWithNamespace added in v0.82.0

func NewEventLogRepositoryWithNamespace[Entity, ID any](m *EventLog, ns string) *EventLogRepository[Entity, ID]

func (*EventLogRepository[Entity, ID]) BeginTx added in v0.82.0

func (s *EventLogRepository[Entity, ID]) BeginTx(ctx context.Context) (context.Context, error)

func (*EventLogRepository[Entity, ID]) CommitTx added in v0.82.0

func (s *EventLogRepository[Entity, ID]) CommitTx(ctx context.Context) error

func (*EventLogRepository[Entity, ID]) Compress added in v0.82.0

func (s *EventLogRepository[Entity, ID]) Compress()

func (*EventLogRepository[Entity, ID]) Create added in v0.82.0

func (s *EventLogRepository[Entity, ID]) Create(ctx context.Context, ptr *Entity) error

func (*EventLogRepository[Entity, ID]) DeleteAll added in v0.82.0

func (s *EventLogRepository[Entity, ID]) DeleteAll(ctx context.Context) error

func (*EventLogRepository[Entity, ID]) DeleteByID added in v0.82.0

func (s *EventLogRepository[Entity, ID]) DeleteByID(ctx context.Context, id ID) error

func (*EventLogRepository[Entity, ID]) Events added in v0.82.0

func (s *EventLogRepository[Entity, ID]) Events(ctx context.Context) []EventLogRepositoryEvent[Entity, ID]

func (*EventLogRepository[Entity, ID]) FindAll added in v0.82.0

func (s *EventLogRepository[Entity, ID]) FindAll(ctx context.Context) iterators.Iterator[Entity]

func (*EventLogRepository[Entity, ID]) FindByID added in v0.82.0

func (s *EventLogRepository[Entity, ID]) FindByID(ctx context.Context, id ID) (_ent Entity, _found bool, _err error)

func (*EventLogRepository[Entity, ID]) FindByIDs added in v0.82.0

func (s *EventLogRepository[Entity, ID]) FindByIDs(ctx context.Context, ids ...ID) iterators.Iterator[Entity]

func (*EventLogRepository[Entity, ID]) GetNamespace added in v0.82.0

func (s *EventLogRepository[Entity, ID]) GetNamespace() string

func (*EventLogRepository[Entity, ID]) LookupTx added in v0.82.0

func (s *EventLogRepository[Entity, ID]) LookupTx(ctx context.Context) (*EventLogTx, bool)

func (*EventLogRepository[Entity, ID]) RollbackTx added in v0.82.0

func (s *EventLogRepository[Entity, ID]) RollbackTx(ctx context.Context) error

func (*EventLogRepository[Entity, ID]) SubscribeToCreate added in v0.82.0

func (s *EventLogRepository[Entity, ID]) SubscribeToCreate(ctx context.Context, subscriber EventLogSubscriber) (pubsub.Subscription, error)

func (*EventLogRepository[Entity, ID]) SubscribeToCreatorEvents added in v0.82.0

func (s *EventLogRepository[Entity, ID]) SubscribeToCreatorEvents(ctx context.Context, subscriber pubsub.CreatorSubscriber[Entity]) (pubsub.Subscription, error)

func (*EventLogRepository[Entity, ID]) SubscribeToDeleteAll added in v0.82.0

func (s *EventLogRepository[Entity, ID]) SubscribeToDeleteAll(ctx context.Context, subscriber EventLogSubscriber) (pubsub.Subscription, error)

func (*EventLogRepository[Entity, ID]) SubscribeToDeleteByID added in v0.82.0

func (s *EventLogRepository[Entity, ID]) SubscribeToDeleteByID(ctx context.Context, subscriber EventLogSubscriber) (pubsub.Subscription, error)

func (*EventLogRepository[Entity, ID]) SubscribeToDeleterEvents added in v0.82.0

func (s *EventLogRepository[Entity, ID]) SubscribeToDeleterEvents(ctx context.Context, subscriber pubsub.DeleterSubscriber[ID]) (pubsub.Subscription, error)

func (*EventLogRepository[Entity, ID]) SubscribeToUpdate added in v0.82.0

func (s *EventLogRepository[Entity, ID]) SubscribeToUpdate(ctx context.Context, subscriber EventLogSubscriber) (pubsub.Subscription, error)

func (*EventLogRepository[Entity, ID]) SubscribeToUpdaterEvents added in v0.82.0

func (s *EventLogRepository[Entity, ID]) SubscribeToUpdaterEvents(ctx context.Context, subscriber pubsub.UpdaterSubscriber[Entity]) (pubsub.Subscription, error)

func (*EventLogRepository[Entity, ID]) Update added in v0.82.0

func (s *EventLogRepository[Entity, ID]) Update(ctx context.Context, ptr *Entity) error

func (*EventLogRepository[Entity, ID]) Upsert added in v0.82.0

func (s *EventLogRepository[Entity, ID]) Upsert(ctx context.Context, ptrs ...*Entity) (rErr error)

func (*EventLogRepository[Entity, ID]) View added in v0.82.0

func (s *EventLogRepository[Entity, ID]) View(ctx context.Context) EventLogRepositoryView[Entity, ID]

type EventLogRepositoryEvent added in v0.82.0

type EventLogRepositoryEvent[Entity, ID any] struct {
	Namespace string
	Name      string
	Value     Entity
	Trace     []Stack
}

func (EventLogRepositoryEvent[Entity, ID]) GetTrace added in v0.82.0

func (e EventLogRepositoryEvent[Entity, ID]) GetTrace() []Stack

func (EventLogRepositoryEvent[Entity, ID]) SetTrace added in v0.82.0

func (e EventLogRepositoryEvent[Entity, ID]) SetTrace(trace []Stack)

func (EventLogRepositoryEvent[Entity, ID]) String added in v0.82.0

func (e EventLogRepositoryEvent[Entity, ID]) String() string

type EventLogRepositoryView added in v0.82.0

type EventLogRepositoryView[Entity, ID any] map[string]Entity

func (EventLogRepositoryView[Entity, ID]) FindByID added in v0.82.0

func (v EventLogRepositoryView[Entity, ID]) FindByID(id ID) (Entity, bool)

type EventLogSubscriber

type EventLogSubscriber interface {
	// Handle handles the the subscribed event.
	// Context may or may not have meta information about the received event.
	// To ensure expectations, define a resource specification <contract> about what must be included in the context.
	Handle(ctx context.Context, event interface{}) error
	// Error allow the subscription implementation to be notified about unexpected situations
	// that needs to be handled by the subscriber.
	// For e.g. the connection is lost and the subscriber might have cached values
	// that must be invalidated on the next successful Handle call
	HandleError(ctx context.Context, err error) error
}

type EventLogTx

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

func (*EventLogTx) Append

func (tx *EventLogTx) Append(ctx context.Context, event Event) error

func (*EventLogTx) Events

func (tx *EventLogTx) Events() []Event

type EventManager

type EventManager interface {
	Append(context.Context, Event) error
	EventViewer
}

type EventViewer

type EventViewer interface {
	Events() []Event
}

type Locker added in v0.98.0

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

Locker is a memory-based shared mutex implementation. Locker is not safe to call from different application instances. Locker is meant to be used in a single application instance.

Example
package main

import (
	"context"

	"github.com/adamluzsi/frameless/adapters/memory"
)

func main() {
	l := memory.NewLocker()

	ctx, err := l.Lock(context.Background())
	if err != nil {
		panic(err)
	}

	if err := l.Unlock(ctx); err != nil {
		panic(err)
	}
}
Output:

func NewLocker added in v0.98.0

func NewLocker() *Locker

func (*Locker) Lock added in v0.98.0

func (l *Locker) Lock(ctx context.Context) (context.Context, error)

func (*Locker) Unlock added in v0.98.0

func (l *Locker) Unlock(ctx context.Context) error

type LockerFactory added in v0.105.0

type LockerFactory[Key comparable] struct {
	// contains filtered or unexported fields
}

func NewLockerFactory added in v0.105.0

func NewLockerFactory[Key comparable]() *LockerFactory[Key]

func (*LockerFactory[Key]) LockerFor added in v0.105.0

func (lf *LockerFactory[Key]) LockerFor(key Key) locks.Locker

type Memory

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

func NewMemory

func NewMemory() *Memory

func (*Memory) All

func (m *Memory) All(T any, ctx context.Context, namespace string) (sliceOfT interface{})

func (*Memory) BeginTx

func (m *Memory) BeginTx(ctx context.Context) (context.Context, error)

func (*Memory) CommitTx

func (m *Memory) CommitTx(ctx context.Context) error

func (*Memory) Del

func (m *Memory) Del(ctx context.Context, namespace string, key string) bool

func (*Memory) Get

func (m *Memory) Get(ctx context.Context, namespace string, key string) (interface{}, bool)

func (*Memory) LookupMeta

func (m *Memory) LookupMeta(ctx context.Context, key string, ptr interface{}) (_found bool, _err error)

func (*Memory) LookupTx

func (m *Memory) LookupTx(ctx context.Context) (*MemoryTx, bool)

func (*Memory) RollbackTx

func (m *Memory) RollbackTx(ctx context.Context) error

func (*Memory) Set

func (m *Memory) Set(ctx context.Context, namespace, key string, value interface{})

func (*Memory) SetMeta

func (m *Memory) SetMeta(ctx context.Context, key string, value interface{}) (context.Context, error)

type MemoryNamespace

type MemoryNamespace map[string]interface{}

type MemoryTx

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

type PubSub added in v0.120.0

type PubSub[Entity any] struct {
	Memory *Memory
	// Namespace allows you to isolate two different PubSub while using the same *Memory
	Namespace string
	// LIFO is a flag to change element ordering from FIFO to LIFO
	LIFO bool
	// Volatile will flag the PubSub to act like a Volatile queue
	Volatile bool
	// blocking will cause the PubSub to wait until the published messages are ACK -ed.
	Blocking bool
}

func (*PubSub[Entity]) Publish added in v0.120.0

func (ps *PubSub[Entity]) Publish(ctx context.Context, vs ...Entity) (rErr error)

func (*PubSub[Entity]) Purge added in v0.120.0

func (ps *PubSub[Entity]) Purge(ctx context.Context) error

func (*PubSub[Entity]) Subscribe added in v0.120.0

func (ps *PubSub[Entity]) Subscribe(ctx context.Context) iterators.Iterator[pubsub.Message[Entity]]

type Repository added in v0.82.0

type Repository[Entity, ID any] struct {
	Memory    *Memory
	MakeID    func(context.Context) (ID, error)
	Namespace string
}

func NewRepository added in v0.82.0

func NewRepository[Entity, ID any](m *Memory) *Repository[Entity, ID]

func NewRepositoryWithNamespace added in v0.82.0

func NewRepositoryWithNamespace[Entity, ID any](m *Memory, ns string) *Repository[Entity, ID]

func (*Repository[Entity, ID]) Create added in v0.82.0

func (s *Repository[Entity, ID]) Create(ctx context.Context, ptr *Entity) error

func (*Repository[Entity, ID]) DeleteAll added in v0.82.0

func (s *Repository[Entity, ID]) DeleteAll(ctx context.Context) error

func (*Repository[Entity, ID]) DeleteByID added in v0.82.0

func (s *Repository[Entity, ID]) DeleteByID(ctx context.Context, id ID) error

func (*Repository[Entity, ID]) FindAll added in v0.82.0

func (s *Repository[Entity, ID]) FindAll(ctx context.Context) iterators.Iterator[Entity]

func (*Repository[Entity, ID]) FindByID added in v0.82.0

func (s *Repository[Entity, ID]) FindByID(ctx context.Context, id ID) (_ent Entity, _found bool, _err error)

func (*Repository[Entity, ID]) FindByIDs added in v0.82.0

func (s *Repository[Entity, ID]) FindByIDs(ctx context.Context, ids ...ID) iterators.Iterator[Entity]

func (*Repository[Entity, ID]) IDToMemoryKey added in v0.82.0

func (s *Repository[Entity, ID]) IDToMemoryKey(id any) string

func (*Repository[Entity, ID]) Update added in v0.82.0

func (s *Repository[Entity, ID]) Update(ctx context.Context, ptr *Entity) error

func (*Repository[Entity, ID]) Upsert added in v0.82.0

func (s *Repository[Entity, ID]) Upsert(ctx context.Context, ptrs ...*Entity) error

type Stack

type Stack struct {
	Path string
	Line int
}

func NewTrace

func NewTrace(offset int) []Stack

func (Stack) RelPath

func (te Stack) RelPath() string

type Subscription

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

func (*Subscription) Close

func (s *Subscription) Close() (rErr error)

type Traceable

type Traceable interface {
	GetTrace() []Stack
	SetTrace([]Stack)
}

Jump to

Keyboard shortcuts

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