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)
- func Scheduler() tasker.Scheduler
- 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)
- type EventLogEvent
- type EventLogRepository
- func (s *EventLogRepository[ENT, ID]) BeginTx(ctx context.Context) (context.Context, error)
- func (s *EventLogRepository[ENT, ID]) CommitTx(ctx context.Context) error
- func (s *EventLogRepository[ENT, ID]) Compress()
- func (s *EventLogRepository[ENT, ID]) Create(ctx context.Context, ptr *ENT) error
- func (s *EventLogRepository[ENT, ID]) DeleteAll(ctx context.Context) error
- func (s *EventLogRepository[ENT, ID]) DeleteByID(ctx context.Context, id ID) error
- func (s *EventLogRepository[ENT, ID]) Events(ctx context.Context) []EventLogRepositoryEvent[ENT, ID]
- func (s *EventLogRepository[ENT, ID]) FindAll(ctx context.Context) (iterators.Iterator[ENT], error)
- func (s *EventLogRepository[ENT, ID]) FindByID(ctx context.Context, id ID) (_ent ENT, _found bool, _err error)
- func (s *EventLogRepository[ENT, ID]) FindByIDs(ctx context.Context, ids ...ID) (iterators.Iterator[ENT], error)
- func (s *EventLogRepository[ENT, ID]) GetNamespace() string
- func (s *EventLogRepository[ENT, ID]) LookupTx(ctx context.Context) (*EventLogTx, bool)
- func (s *EventLogRepository[ENT, ID]) RollbackTx(ctx context.Context) error
- func (s *EventLogRepository[ENT, ID]) Save(ctx context.Context, ptr *ENT) (rErr error)
- func (s *EventLogRepository[ENT, ID]) Update(ctx context.Context, ptr *ENT) error
- func (s *EventLogRepository[ENT, ID]) View(ctx context.Context) EventLogRepositoryView[ENT, 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 Lock
- 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
- func (q *Queue[Data]) BeginTx(ctx context.Context) (context.Context, error)
- func (q *Queue[Data]) CommitTx(ctx context.Context) error
- func (q *Queue[Data]) Publish(ctx context.Context, vs ...Data) (rErr error)
- func (q *Queue[Data]) Purge(ctx context.Context) error
- func (q *Queue[Data]) RollbackTx(ctx context.Context) error
- func (q *Queue[Data]) Subscribe(ctx context.Context) (pubsub.Subscription[Data], error)
- type QueueSubscription
- type Repository
- func (r *Repository[ENT, ID]) BeginTx(ctx context.Context) (context.Context, error)
- func (r *Repository[ENT, ID]) CommitTx(ctx context.Context) error
- func (r *Repository[ENT, ID]) Create(ctx context.Context, ptr *ENT) error
- func (r *Repository[ENT, ID]) DeleteAll(ctx context.Context) error
- func (r *Repository[ENT, ID]) DeleteByID(ctx context.Context, id ID) error
- func (r *Repository[ENT, ID]) FindAll(ctx context.Context) (iterators.Iterator[ENT], error)
- func (r *Repository[ENT, ID]) FindByID(ctx context.Context, id ID) (_ent ENT, _found bool, _err error)
- func (r *Repository[ENT, ID]) FindByIDs(ctx context.Context, ids ...ID) (iterators.Iterator[ENT], error)
- func (r *Repository[ENT, ID]) IDToMemoryKey(id any) string
- func (r *Repository[ENT, ID]) QueryMany(ctx context.Context, filter func(v ENT) bool) (iterators.Iterator[ENT], error)
- func (r *Repository[ENT, ID]) QueryOne(ctx context.Context, filter func(v ENT) bool) (ENT, bool, error)
- func (r *Repository[ENT, ID]) RollbackTx(ctx context.Context) error
- func (r *Repository[ENT, ID]) Save(ctx context.Context, ptr *ENT) (rErr error)
- func (r *Repository[ENT, ID]) Update(ctx context.Context, ptr *ENT) error
- type Stack
- type Traceable
Examples ¶
Constants ¶
const ( CreateEvent = `Create` SaveEvent = `Save` UpdateEvent = `Update` DeleteAllEvent = `DeleteAll` DeleteByIDEvent = `DeleteByID` )
Name Types
const ErrMissingID errorkit.Error = "ErrMissingID"
Variables ¶
This section is empty.
Functions ¶
func LogHistoryOnFailure ¶
func LogHistoryOnFailure(tb testingTB, el EventViewer)
func RewriteEventLog ¶
Types ¶
type CacheRepository ¶
func NewCacheRepository ¶
func NewCacheRepository[Entity, ID any](m *Memory) *CacheRepository[Entity, ID]
func (*CacheRepository[Entity, ID]) CommitTx ¶
func (cr *CacheRepository[Entity, ID]) CommitTx(ctx context.Context) error
func (*CacheRepository[Entity, ID]) Entities ¶
func (cr *CacheRepository[Entity, ID]) Entities() cache.EntityRepository[Entity, ID]
func (*CacheRepository[Entity, ID]) Hits ¶
func (cr *CacheRepository[Entity, ID]) Hits() cache.HitRepository[ID]
func (*CacheRepository[Entity, ID]) RollbackTx ¶
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 ¶
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 ¶
type EventLogRepository[ENT, 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 ¶
func NewEventLogRepository[ENT, ID any](m *EventLog) *EventLogRepository[ENT, ID]
func NewEventLogRepositoryWithNamespace ¶
func NewEventLogRepositoryWithNamespace[ENT, ID any](m *EventLog, ns string) *EventLogRepository[ENT, ID]
func (*EventLogRepository[ENT, ID]) CommitTx ¶
func (s *EventLogRepository[ENT, ID]) CommitTx(ctx context.Context) error
func (*EventLogRepository[ENT, ID]) Compress ¶
func (s *EventLogRepository[ENT, ID]) Compress()
func (*EventLogRepository[ENT, ID]) Create ¶
func (s *EventLogRepository[ENT, ID]) Create(ctx context.Context, ptr *ENT) error
func (*EventLogRepository[ENT, ID]) DeleteAll ¶
func (s *EventLogRepository[ENT, ID]) DeleteAll(ctx context.Context) error
func (*EventLogRepository[ENT, ID]) DeleteByID ¶
func (s *EventLogRepository[ENT, ID]) DeleteByID(ctx context.Context, id ID) error
func (*EventLogRepository[ENT, ID]) Events ¶
func (s *EventLogRepository[ENT, ID]) Events(ctx context.Context) []EventLogRepositoryEvent[ENT, ID]
func (*EventLogRepository[ENT, ID]) FindByID ¶
func (s *EventLogRepository[ENT, ID]) FindByID(ctx context.Context, id ID) (_ent ENT, _found bool, _err error)
func (*EventLogRepository[ENT, ID]) GetNamespace ¶
func (s *EventLogRepository[ENT, ID]) GetNamespace() string
func (*EventLogRepository[ENT, ID]) LookupTx ¶
func (s *EventLogRepository[ENT, ID]) LookupTx(ctx context.Context) (*EventLogTx, bool)
func (*EventLogRepository[ENT, ID]) RollbackTx ¶
func (s *EventLogRepository[ENT, ID]) RollbackTx(ctx context.Context) error
func (*EventLogRepository[ENT, ID]) Save ¶ added in v0.242.0
func (s *EventLogRepository[ENT, ID]) Save(ctx context.Context, ptr *ENT) (rErr error)
func (*EventLogRepository[ENT, ID]) Update ¶
func (s *EventLogRepository[ENT, ID]) Update(ctx context.Context, ptr *ENT) error
func (*EventLogRepository[ENT, ID]) View ¶
func (s *EventLogRepository[ENT, ID]) View(ctx context.Context) EventLogRepositoryView[ENT, ID]
type EventLogRepositoryEvent ¶
type EventLogRepositoryEvent[ENT, ID any] struct { Namespace string Name string Value ENT Trace []Stack }
func (EventLogRepositoryEvent[ENT, ID]) GetTrace ¶
func (e EventLogRepositoryEvent[ENT, ID]) GetTrace() []Stack
func (EventLogRepositoryEvent[ENT, ID]) SetTrace ¶
func (e EventLogRepositoryEvent[ENT, ID]) SetTrace(trace []Stack)
func (EventLogRepositoryEvent[ENT, ID]) String ¶
func (e EventLogRepositoryEvent[ENT, ID]) String() string
type EventLogRepositoryView ¶
func (EventLogRepositoryView[ENT, ID]) FindByID ¶
func (v EventLogRepositoryView[ENT, ID]) FindByID(id ID) (ENT, 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 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 ¶
type FanOutExchange[Data any] struct { // 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 ¶
func (e *FanOutExchange[Data]) MakeQueue() *Queue[Data]
MakeQueue creates a unique queue which is bound to the FanOut exchange.
type FileSystem ¶
type FileSystem struct {
// contains filtered or unexported fields
}
Example ¶
package main import ( "fmt" "io" "io/fs" "os" "path/filepath" "go.llib.dev/frameless/adapter/memory" "go.llib.dev/frameless/port/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 }) }
func (*FileSystem) OpenFile ¶
func (mfs *FileSystem) OpenFile(name string, flag int, perm fs.FileMode) (filesystem.File, error)
func (*FileSystem) Remove ¶
func (mfs *FileSystem) Remove(name string) error
type FileSystemFile ¶
type FileSystemFile struct {
// contains filtered or unexported fields
}
func (*FileSystemFile) Close ¶
func (f *FileSystemFile) Close() error
func (*FileSystemFile) Seek ¶
func (f *FileSystemFile) Seek(offset int64, whence int) (int64, error)
func (*FileSystemFile) Sync ¶
func (f *FileSystemFile) Sync() error
type Lock ¶ added in v0.247.0
type Lock struct {
// contains filtered or unexported fields
}
Lock is a memory-based implementation of guard.Lock. Lock is not safe to call from different application instances. Lock is meant to be used in a single application instance.
type LockerFactory ¶
type LockerFactory[Key comparable] struct { // contains filtered or unexported fields }
func NewLockerFactory ¶
func NewLockerFactory[Key comparable]() *LockerFactory[Key]
func NewTaskerSchedulerLocks ¶ added in v0.246.0
func NewTaskerSchedulerLocks() *LockerFactory[tasker.ScheduleID]
func (*LockerFactory[Key]) LockerFor ¶
func (lf *LockerFactory[Key]) LockerFor(key Key) guard.Locker
func (*LockerFactory[Key]) NonBlockingLockerFor ¶ added in v0.247.0
func (lf *LockerFactory[Key]) NonBlockingLockerFor(key Key) guard.NonBlockingLocker
type Memory ¶
type Memory struct {
// contains filtered or unexported fields
}
func (*Memory) LookupMeta ¶
type MemoryNamespace ¶
type MemoryNamespace map[string]interface{}
type Queue ¶
type Queue[Data any] struct { // 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 // SortLessFunc will define how to sort data, when we look for what message to handle next. // if not supplied FIFO is the default ordering. SortLessFunc func(i Data, j Data) bool // contains filtered or unexported fields }
func (*Queue[Data]) BeginTx ¶ added in v0.244.0
BeginTx creates a context with a transaction. All statements that receive this context should be executed within the given transaction in the context. After a BeginTx command will be executed in a single transaction until an explicit COMMIT or ROLLBACK is given.
In case the resource support some form of isolation level, or other ACID related property of the transaction, then it is advised to prepare this information in the context before calling BeginTx. e.g.:
... var err error ctx = r.ContextWithIsolationLevel(ctx, sql.LevelSerializable) ctx, err = r.BeginTx(ctx)
func (*Queue[Data]) CommitTx ¶ added in v0.244.0
CommitTx Commit commits the current transaction. All changes made by the transaction become visible to others and are guaranteed to be durable if a crash occurs.
func (*Queue[Data]) RollbackTx ¶ added in v0.244.0
RollbackTx rolls back the current transaction and causes all the updates made by the transaction to be discarded.
type QueueSubscription ¶ added in v0.244.0
type QueueSubscription[Data any] struct { // contains filtered or unexported fields }
func (*QueueSubscription[Data]) Close ¶ added in v0.244.0
func (pss *QueueSubscription[Data]) Close() error
func (*QueueSubscription[Data]) Err ¶ added in v0.244.0
func (s *QueueSubscription[Data]) Err() error
func (*QueueSubscription[Data]) Next ¶ added in v0.244.0
func (s *QueueSubscription[Data]) Next() bool
func (*QueueSubscription[Data]) Value ¶ added in v0.244.0
func (s *QueueSubscription[Data]) Value() pubsub.Message[Data]
type Repository ¶
type Repository[ENT, ID any] struct { // Memory [optional] is the backing store for this Repository. // // default: NewMemory() Memory *Memory // Namespace [optional] Namespace string // IDA [optional] is the ID Accessor that maps the ID to the ENT field. IDA extid.Accessor[ENT, ID] // MakeID [optional] is an optional field if you need a specific way of generating new IDs during creation. MakeID func(context.Context) (ID, error) // ExpectID [optional] is a test simulator flag that allows you to enforce the user of this Repository, // to populate the ID field of ENT prior to calling Create or Save, else the operation will fail. ExpectID bool // contains filtered or unexported fields }
func NewRepository ¶
func NewRepository[ENT, ID any](m *Memory) *Repository[ENT, ID]
func NewRepositoryWithNamespace ¶
func NewRepositoryWithNamespace[ENT, ID any](m *Memory, ns string) *Repository[ENT, ID]
func NewTaskerSchedulerStateRepository ¶ added in v0.246.0
func NewTaskerSchedulerStateRepository() *Repository[tasker.ScheduleState, tasker.ScheduleID]
func (*Repository[ENT, ID]) CommitTx ¶ added in v0.238.0
func (r *Repository[ENT, ID]) CommitTx(ctx context.Context) error
func (*Repository[ENT, ID]) Create ¶
func (r *Repository[ENT, ID]) Create(ctx context.Context, ptr *ENT) error
func (*Repository[ENT, ID]) DeleteAll ¶
func (r *Repository[ENT, ID]) DeleteAll(ctx context.Context) error
func (*Repository[ENT, ID]) DeleteByID ¶
func (r *Repository[ENT, ID]) DeleteByID(ctx context.Context, id ID) error
func (*Repository[ENT, ID]) FindByID ¶
func (r *Repository[ENT, ID]) FindByID(ctx context.Context, id ID) (_ent ENT, _found bool, _err error)
func (*Repository[ENT, ID]) IDToMemoryKey ¶
func (r *Repository[ENT, ID]) IDToMemoryKey(id any) string
func (*Repository[ENT, ID]) RollbackTx ¶ added in v0.238.0
func (r *Repository[ENT, ID]) RollbackTx(ctx context.Context) error