Documentation ¶
Index ¶
- Constants
- func LogHistoryOnFailure(tb testingTB, el EventViewer)
- func MakeID[ID any](context.Context) (ID, error)
- func RewriteEventLog[EventType any](el *EventLog, rewrite func(es []EventType) []EventType)
- type CacheRepository
- func (cr *CacheRepository[Entity, ID]) BeginTx(ctx context.Context) (context.Context, error)
- func (cr *CacheRepository[Entity, ID]) CommitTx(ctx context.Context) error
- func (cr *CacheRepository[Entity, ID]) Entities() cache.EntityRepository[Entity, ID]
- func (cr *CacheRepository[Entity, ID]) Hits() cache.HitRepository[ID]
- func (cr *CacheRepository[Entity, ID]) RollbackTx(ctx context.Context) error
- type Event
- type EventLog
- func (el *EventLog) Append(ctx context.Context, event Event) error
- func (el *EventLog) Atomic(ctx context.Context, fn func(tx *EventLogTx) error) error
- func (el *EventLog) BeginTx(ctx context.Context) (context.Context, error)
- func (el *EventLog) CommitTx(ctx context.Context) error
- func (el *EventLog) Compress()
- func (el *EventLog) Events() []Event
- func (el *EventLog) EventsInContext(ctx context.Context) []Event
- func (el *EventLog) LookupMeta(ctx context.Context, key string, ptr interface{}) (_found bool, _err error)
- func (el *EventLog) LookupTx(ctx context.Context) (*EventLogTx, bool)
- func (el *EventLog) Rewrite(mapper func(es []Event) []Event)
- func (el *EventLog) RollbackTx(ctx context.Context) error
- func (el *EventLog) SetMeta(ctx context.Context, key string, value interface{}) (context.Context, error)
- func (el *EventLog) Subscribe(ctx context.Context, subscriber EventLogSubscriber) (pubsub.Subscription, error)
- type EventLogEvent
- type EventLogRepository
- func (s *EventLogRepository[Entity, ID]) BeginTx(ctx context.Context) (context.Context, error)
- func (s *EventLogRepository[Entity, ID]) CommitTx(ctx context.Context) error
- func (s *EventLogRepository[Entity, ID]) Compress()
- func (s *EventLogRepository[Entity, ID]) Create(ctx context.Context, ptr *Entity) error
- func (s *EventLogRepository[Entity, ID]) DeleteAll(ctx context.Context) error
- func (s *EventLogRepository[Entity, ID]) DeleteByID(ctx context.Context, id ID) error
- func (s *EventLogRepository[Entity, ID]) Events(ctx context.Context) []EventLogRepositoryEvent[Entity, ID]
- func (s *EventLogRepository[Entity, ID]) FindAll(ctx context.Context) iterators.Iterator[Entity]
- func (s *EventLogRepository[Entity, ID]) FindByID(ctx context.Context, id ID) (_ent Entity, _found bool, _err error)
- func (s *EventLogRepository[Entity, ID]) FindByIDs(ctx context.Context, ids ...ID) iterators.Iterator[Entity]
- func (s *EventLogRepository[Entity, ID]) GetNamespace() string
- func (s *EventLogRepository[Entity, ID]) LookupTx(ctx context.Context) (*EventLogTx, bool)
- func (s *EventLogRepository[Entity, ID]) RollbackTx(ctx context.Context) error
- func (s *EventLogRepository[Entity, ID]) SubscribeToCreate(ctx context.Context, subscriber EventLogSubscriber) (pubsub.Subscription, error)
- func (s *EventLogRepository[Entity, ID]) SubscribeToCreatorEvents(ctx context.Context, subscriber pubsub.CreatorSubscriber[Entity]) (pubsub.Subscription, error)
- func (s *EventLogRepository[Entity, ID]) SubscribeToDeleteAll(ctx context.Context, subscriber EventLogSubscriber) (pubsub.Subscription, error)
- func (s *EventLogRepository[Entity, ID]) SubscribeToDeleteByID(ctx context.Context, subscriber EventLogSubscriber) (pubsub.Subscription, error)
- func (s *EventLogRepository[Entity, ID]) SubscribeToDeleterEvents(ctx context.Context, subscriber pubsub.DeleterSubscriber[ID]) (pubsub.Subscription, error)
- func (s *EventLogRepository[Entity, ID]) SubscribeToUpdate(ctx context.Context, subscriber EventLogSubscriber) (pubsub.Subscription, error)
- func (s *EventLogRepository[Entity, ID]) SubscribeToUpdaterEvents(ctx context.Context, subscriber pubsub.UpdaterSubscriber[Entity]) (pubsub.Subscription, error)
- func (s *EventLogRepository[Entity, ID]) Update(ctx context.Context, ptr *Entity) error
- func (s *EventLogRepository[Entity, ID]) Upsert(ctx context.Context, ptrs ...*Entity) (rErr error)
- func (s *EventLogRepository[Entity, ID]) View(ctx context.Context) EventLogRepositoryView[Entity, ID]
- type EventLogRepositoryEvent
- type EventLogRepositoryView
- type EventLogSubscriber
- type EventLogTx
- type EventManager
- type EventViewer
- type FanOutExchange
- type FileSystem
- type FileSystemFile
- func (f *FileSystemFile) Close() error
- func (f *FileSystemFile) Read(bytes []byte) (int, error)
- func (f *FileSystemFile) ReadDir(n int) ([]fs.DirEntry, error)
- func (f *FileSystemFile) Seek(offset int64, whence int) (int64, error)
- func (f *FileSystemFile) Stat() (fs.FileInfo, error)
- func (f *FileSystemFile) Sync() error
- func (f *FileSystemFile) Write(p []byte) (n int, err error)
- type Locker
- type LockerFactory
- type Memory
- func (m *Memory) All(T any, ctx context.Context, namespace string) (sliceOfT interface{})
- func (m *Memory) BeginTx(ctx context.Context) (context.Context, error)
- func (m *Memory) CommitTx(ctx context.Context) error
- func (m *Memory) Del(ctx context.Context, namespace string, key string) bool
- func (m *Memory) Get(ctx context.Context, namespace string, key string) (interface{}, bool)
- func (m *Memory) LookupMeta(ctx context.Context, key string, ptr interface{}) (_found bool, _err error)
- func (m *Memory) LookupTx(ctx context.Context) (*MemoryTx, bool)
- func (m *Memory) RollbackTx(ctx context.Context) error
- func (m *Memory) Set(ctx context.Context, namespace, key string, value interface{})
- func (m *Memory) SetMeta(ctx context.Context, key string, value interface{}) (context.Context, error)
- type MemoryNamespace
- type MemoryTx
- type Queue
- type Repository
- func (s *Repository[Entity, ID]) Create(ctx context.Context, ptr *Entity) error
- func (s *Repository[Entity, ID]) DeleteAll(ctx context.Context) error
- func (s *Repository[Entity, ID]) DeleteByID(ctx context.Context, id ID) error
- func (s *Repository[Entity, ID]) FindAll(ctx context.Context) iterators.Iterator[Entity]
- func (s *Repository[Entity, ID]) FindByID(ctx context.Context, id ID) (_ent Entity, _found bool, _err error)
- func (s *Repository[Entity, ID]) FindByIDs(ctx context.Context, ids ...ID) iterators.Iterator[Entity]
- func (s *Repository[Entity, ID]) IDToMemoryKey(id any) string
- func (s *Repository[Entity, ID]) Update(ctx context.Context, ptr *Entity) error
- func (s *Repository[Entity, ID]) Upsert(ctx context.Context, ptrs ...*Entity) error
- type Stack
- type Subscription
- type Traceable
Examples ¶
Constants ¶
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 RewriteEventLog ¶
Types ¶
type CacheRepository ¶ added in v0.125.0
func NewCacheRepository ¶ added in v0.125.0
func NewCacheRepository[Entity, ID any](m *Memory) *CacheRepository[Entity, ID]
func (*CacheRepository[Entity, ID]) CommitTx ¶ added in v0.125.0
func (cr *CacheRepository[Entity, ID]) CommitTx(ctx context.Context) error
func (*CacheRepository[Entity, ID]) Entities ¶ added in v0.126.0
func (cr *CacheRepository[Entity, ID]) Entities() cache.EntityRepository[Entity, ID]
func (*CacheRepository[Entity, ID]) Hits ¶ added in v0.126.0
func (cr *CacheRepository[Entity, ID]) Hits() cache.HitRepository[ID]
func (*CacheRepository[Entity, ID]) RollbackTx ¶ added in v0.125.0
func (cr *CacheRepository[Entity, ID]) RollbackTx(ctx context.Context) error
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) LookupMeta ¶
func (*EventLog) Subscribe ¶
func (el *EventLog) Subscribe(ctx context.Context, subscriber EventLogSubscriber) (pubsub.Subscription, error)
type EventLogEvent ¶
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]) 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
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) 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 FanOutExchange ¶ added in v0.128.0
type FanOutExchange[Data any] struct { Memory *Memory // Namespace allows you to isolate two different FanOutExchange while using the same *Memory Namespace string // Queues contain every Queue that suppose to be bound to the FanOut Exchange Queues []*Queue[Data] }
FanOutExchange delivers messages to all the queues that are bound to it. This is useful when you want to broadcast a message to multiple consumers.
func (*FanOutExchange[Data]) MakeQueue ¶ added in v0.128.0
func (e *FanOutExchange[Data]) MakeQueue() *Queue[Data]
MakeQueue creates a unique queue which is bound to the FanOut exchange.
type FileSystem ¶ added in v0.121.0
type FileSystem struct {
// contains filtered or unexported fields
}
Example ¶
package main import ( "fmt" "github.com/adamluzsi/frameless/adapters/memory" "io" "io/fs" "os" "path/filepath" "github.com/adamluzsi/frameless/ports/filesystem" ) func main() { fsys := &memory.FileSystem{} file, err := fsys.OpenFile("test", os.O_RDWR|os.O_CREATE|os.O_EXCL, filesystem.ModeUserRWX) if err != nil { panic(err) } defer file.Close() file.Write([]byte("Hello world!")) file.Seek(0, io.SeekStart) bs, err := io.ReadAll(file) if err != nil { panic(err) } fmt.Println(string(bs)) // "Hello world!" file.Close() fsys.Remove("test") fsys.Mkdir("a", filesystem.ModeUserRWX) file2Name := filepath.Join("a", "test.txt") file2, err := filesystem.Create(fsys, file2Name) if err != nil { panic(err) } file2.Close() file2, err = filesystem.Open(fsys, file2Name) if err != nil { panic(err) } file2.Close() filesystem.WalkDir(fsys, ".", func(path string, d fs.DirEntry, err error) error { return fs.SkipDir }) }
Output:
func (*FileSystem) Mkdir ¶ added in v0.121.0
func (mfs *FileSystem) Mkdir(name string, perm fs.FileMode) error
func (*FileSystem) OpenFile ¶ added in v0.121.0
func (mfs *FileSystem) OpenFile(name string, flag int, perm fs.FileMode) (filesystem.File, error)
func (*FileSystem) Remove ¶ added in v0.121.0
func (mfs *FileSystem) Remove(name string) error
type FileSystemFile ¶ added in v0.121.0
type FileSystemFile struct {
// contains filtered or unexported fields
}
func (*FileSystemFile) Close ¶ added in v0.121.0
func (f *FileSystemFile) Close() error
func (*FileSystemFile) Read ¶ added in v0.121.0
func (f *FileSystemFile) Read(bytes []byte) (int, error)
func (*FileSystemFile) ReadDir ¶ added in v0.121.0
func (f *FileSystemFile) ReadDir(n int) ([]fs.DirEntry, error)
func (*FileSystemFile) Seek ¶ added in v0.121.0
func (f *FileSystemFile) Seek(offset int64, whence int) (int64, error)
func (*FileSystemFile) Stat ¶ added in v0.121.0
func (f *FileSystemFile) Stat() (fs.FileInfo, error)
func (*FileSystemFile) Sync ¶ added in v0.121.0
func (f *FileSystemFile) Sync() error
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:
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 (*Memory) LookupMeta ¶
type MemoryNamespace ¶
type MemoryNamespace map[string]interface{}
type Queue ¶ added in v0.128.0
type Queue[Data any] struct { Memory *Memory // Namespace allows you to isolate two different Queue 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 Queue to act like a Volatile queue Volatile bool // blocking will cause the Queue to wait until the published messages are ACK -ed. Blocking bool }
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
type Subscription ¶
type Subscription struct {
// contains filtered or unexported fields
}
func (*Subscription) Close ¶
func (s *Subscription) Close() (rErr error)