Documentation ¶
Index ¶
- func Abort(ctx context.Context)
- func CopyEntity(typeFullname string, entity any) any
- func CopyEntityInProcess(ctx context.Context, entityType string, id any) any
- func EntityAvailableInProcess(ctx context.Context, entityType string, id any) bool
- func Finish(ctx context.Context) error
- func GetFromOrPutEntityToProcessIfNotAvailable(ctx context.Context, entityType string, id any, entity any) (actual any, get bool)
- func Go(ctx context.Context, f func(ctx context.Context) error) (err error)
- func PutNewEntityToProcess(ctx context.Context, entityType string, id any, entity any)
- func RemoveEntityInProcess(ctx context.Context, entityType string, id any)
- func Start(ctx context.Context) context.Context
- func TakeEntityInProcess(ctx context.Context, entityType string, id any) (exists bool, entity any)
- func TakenFromRepository(ctx context.Context, entityType string, id any, entity any)
- func TakenFromSingletonRepository(ctx context.Context, entityType string)
- type CreatedInProcState
- type ErrorState
- type MockMutexes
- type MockQueryFuncs
- type MockStore
- func (store *MockStore[T]) Load(ctx context.Context, id any) (entity T, found bool, err error)
- func (store *MockStore[T]) RemoveAll(ctx context.Context, ids []any) error
- func (store *MockStore[T]) Save(ctx context.Context, id any, entity T) error
- func (store *MockStore[T]) SaveAll(ctx context.Context, entitiesToInsert map[any]any, ...) error
- type Mutexes
- type NewZeroEntity
- type ProcessContext
- type ProcessEntity
- type ProcessEntityState
- type Repository
- type RepositoryImpl
- func (repository *RepositoryImpl[T]) EntityType() string
- func (repository *RepositoryImpl[T]) Find(ctx context.Context, id any) (entity T, found bool)
- func (repository *RepositoryImpl[T]) FlushProcessEntities(ctx context.Context, entitiesToInsert map[any]any, ...) error
- func (repository *RepositoryImpl[T]) Put(ctx context.Context, id any, entity T)
- func (repository *RepositoryImpl[T]) PutIfAbsent(ctx context.Context, id any, entity T) (actual T, absent bool)
- func (repository *RepositoryImpl[T]) ReleaseProcessEntities(ctx context.Context, ids []any)
- func (repository *RepositoryImpl[T]) Remove(ctx context.Context, id any) (removed T, exists bool)
- func (repository *RepositoryImpl[T]) Take(ctx context.Context, id any) (entity T, found bool)
- func (repository *RepositoryImpl[T]) TakeOrPutIfAbsent(ctx context.Context, id any, newEntity T) T
- type SingletonRepository
- type SingletonRepositoryImpl
- func (repo *SingletonRepositoryImpl[T]) Get(ctx context.Context) (*T, error)
- func (repo *SingletonRepositoryImpl[T]) Put(ctx context.Context, entity *T) error
- func (repo *SingletonRepositoryImpl[T]) ReleaseProcessEntity(ctx context.Context)
- func (repo *SingletonRepositoryImpl[T]) Take(ctx context.Context) (*T, error)
- type Store
- type TakenFromRepoState
- type ToRemoveInRepoState
- type TransientInProcState
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CopyEntity ¶
完整复制一个实体(深拷贝),这里约定,实体只能是一个struct,实体的field只能是基本类型或者实体或者集合(Array,Map,Slice),集合的元素只能是基本类型或者实体
func CopyEntityInProcess ¶
func PutNewEntityToProcess ¶
func RemoveEntityInProcess ¶
func TakeEntityInProcess ¶
func TakenFromRepository ¶
Types ¶
type MockMutexes ¶
type MockMutexes struct { }
func NewMockMutexes ¶
func NewMockMutexes() *MockMutexes
func (*MockMutexes) NewAndLock ¶
type MockQueryFuncs ¶
type MockQueryFuncs[T any] struct { }
func (*MockQueryFuncs[T]) Count ¶
func (qf *MockQueryFuncs[T]) Count(ctx context.Context) (uint64, error)
func (*MockQueryFuncs[T]) QueryAllByField ¶
func (*MockQueryFuncs[T]) QueryAllIds ¶
func (qf *MockQueryFuncs[T]) QueryAllIds(ctx context.Context) (ids []any, err error)
type MockStore ¶
type MockStore[T any] struct { // contains filtered or unexported fields }
func NewMockStore ¶
type NewZeroEntity ¶
type NewZeroEntity[T any] func() T
type ProcessContext ¶
type ProcessContext struct {
// contains filtered or unexported fields
}
收集,共享,输出一个过程中的数据。包括过程信息,过程中涉及到的实体的状态变化
type ProcessEntity ¶
type ProcessEntity struct {
// contains filtered or unexported fields
}
在当前过程当中的实体
func (*ProcessEntity) Entity ¶
func (pe *ProcessEntity) Entity() any
func (*ProcessEntity) State ¶
func (pe *ProcessEntity) State() ProcessEntityState
type ProcessEntityState ¶
type ProcessEntityState interface {
// contains filtered or unexported methods
}
过程当中的实体的可能的几种状态
type Repository ¶
type Repository[T any] interface { Find(ctx context.Context, id any) (entity T, found bool) Take(ctx context.Context, id any) (entity T, found bool) Put(ctx context.Context, id any, entity T) PutIfAbsent(ctx context.Context, id any, entity T) (actual T, absent bool) Remove(ctx context.Context, id any) (removed T, exists bool) TakeOrPutIfAbsent(ctx context.Context, id any, newEntity T) T }
仓库是存放聚合的地方,聚合只会通过它的id来获取。 仓库是一个接口,是为了清晰地罗列它的功能,除此之外没有其他特别的原因。 泛型类型T代表聚合的类型,仓库创建的时候决定T的实际类型, 例如: repoimpl.NewMemRepository(func() *Order { return &Order{} }) 这里创建了一个实际类型为“Order”的内存仓库 repoimpl.NewMemRepository(func() *Product { return &Product{} }) 这里创建了一个实际类型为“Product”的内存仓库
func NewMockRepository ¶
func NewMockRepository[T any](newZeroEntityFunc NewZeroEntity[T]) Repository[T]
func NewRepository ¶
func NewRepository[T any](store Store[T], mutexes Mutexes, newZeroEntityFunc NewZeroEntity[T]) Repository[T]
type RepositoryImpl ¶
type RepositoryImpl[T any] struct { // contains filtered or unexported fields }
func (*RepositoryImpl[T]) EntityType ¶
func (repository *RepositoryImpl[T]) EntityType() string
func (*RepositoryImpl[T]) Find ¶
func (repository *RepositoryImpl[T]) Find(ctx context.Context, id any) (entity T, found bool)
func (*RepositoryImpl[T]) FlushProcessEntities ¶
func (repository *RepositoryImpl[T]) FlushProcessEntities(ctx context.Context, entitiesToInsert map[any]any, entitiesToUpdate map[any]*ProcessEntity, idsToRemoveEntity []any) error
func (*RepositoryImpl[T]) Put ¶
func (repository *RepositoryImpl[T]) Put(ctx context.Context, id any, entity T)
func (*RepositoryImpl[T]) PutIfAbsent ¶
func (repository *RepositoryImpl[T]) PutIfAbsent(ctx context.Context, id any, entity T) (actual T, absent bool)
func (*RepositoryImpl[T]) ReleaseProcessEntities ¶
func (repository *RepositoryImpl[T]) ReleaseProcessEntities(ctx context.Context, ids []any)
func (*RepositoryImpl[T]) Remove ¶
func (repository *RepositoryImpl[T]) Remove(ctx context.Context, id any) (removed T, exists bool)
func (*RepositoryImpl[T]) Take ¶
func (repository *RepositoryImpl[T]) Take(ctx context.Context, id any) (entity T, found bool)
func (*RepositoryImpl[T]) TakeOrPutIfAbsent ¶
func (repository *RepositoryImpl[T]) TakeOrPutIfAbsent(ctx context.Context, id any, newEntity T) T
type SingletonRepository ¶
type SingletonRepository[T any] interface { Get(ctx context.Context) (*T, error) Take(ctx context.Context) (*T, error) Put(ctx context.Context, entity *T) error }
保存的是一个不存在于某个集合当中的独立的实体。只在内存中,如需从数据库加载初始数据,则在系统启动时完成加载
func NewSingletonRepository ¶
func NewSingletonRepository[T any](entity *T) SingletonRepository[T]
type SingletonRepositoryImpl ¶
type SingletonRepositoryImpl[T any] struct { // contains filtered or unexported fields }
func (*SingletonRepositoryImpl[T]) Get ¶
func (repo *SingletonRepositoryImpl[T]) Get(ctx context.Context) (*T, error)
func (*SingletonRepositoryImpl[T]) Put ¶
func (repo *SingletonRepositoryImpl[T]) Put(ctx context.Context, entity *T) error
func (*SingletonRepositoryImpl[T]) ReleaseProcessEntity ¶
func (repo *SingletonRepositoryImpl[T]) ReleaseProcessEntity(ctx context.Context)
type Store ¶
type Store[T any] interface { //加载上来的是原始entity的一个副本(copy),基于数据库的store天然就是copy,而内存store需要实现copy而不能传递原始entity的指针 Load(ctx context.Context, id any) (entity T, found bool, err error) Save(ctx context.Context, id any, entity T) error SaveAll(ctx context.Context, entitiesToInsert map[any]any, entitiesToUpdate map[any]*ProcessEntity) error RemoveAll(ctx context.Context, ids []any) error }
Click to show internal directories.
Click to hide internal directories.