Documentation
¶
Index ¶
- Variables
- type DataMap
- type Dumper
- type InMemoryStorage
- func (s *InMemoryStorage[TData]) Delete(user string, storeName string) error
- func (s *InMemoryStorage[TData]) Get(user string, out *TData) error
- func (s *InMemoryStorage[TData]) IsDirty() bool
- func (s *InMemoryStorage[TData]) List(user UID) ([]string, error)
- func (s *InMemoryStorage[TData]) Load(ctx context.Context) error
- func (s *InMemoryStorage[TData]) Save(ctx context.Context) error
- func (s *InMemoryStorage[TData]) Set(user string, in *TData) error
- func (s *InMemoryStorage[TData]) Update(user string, storeName string, updateFn func(*TData) (*TData, error)) error
- type SavingFunc
- type StorableType
- type Storage
- type UID
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrUserNotFound is returned when a user is not found ErrUserNotFound = fmt.Errorf("user not found") // ErrInvalidInput is returned when the input is invalid ErrInvalidInput = fmt.Errorf("invalid input") // ErrInvalidUser is returned when the user is invalid ErrInvalidUser = fmt.Errorf("invalid user") // ErrStatusError is returned when the status is invalid ErrStatusError = fmt.Errorf("status error") )
Functions ¶
This section is empty.
Types ¶
type Dumper ¶
type Dumper[T any] interface { // Dump dumps memory data to a permanent storage Dump(ctx context.Context, permanentKey string, data map[UID]DataMap[T]) error // Load loads data from a permanent storage to memory Load(ctx context.Context, permanentKey string, out *map[UID]DataMap[T]) error }
Dumper is a function that dumps memory data to a permanent storage, or loads data from a permanent storage to memory
type InMemoryStorage ¶
type InMemoryStorage[TData StorableType] struct {
// PersistentKey is the permanent key of the storage
PersistentKey string
// Dumper is a function that dumps memory data to a permanent storage,
Dumper Dumper[TData]
// contains filtered or unexported fields
}
InMemoryStorage is an in-memory implementation of Storage
func NewInMemoryStorage ¶
func NewInMemoryStorage[TData StorableType](persistentKey string) *InMemoryStorage[TData]
NewInMemoryStorage creates a new instance of InMemoryResourceStorage
func (*InMemoryStorage[TData]) IsDirty ¶
func (s *InMemoryStorage[TData]) IsDirty() bool
IsDirty returns true if the storage has been modified since
func (*InMemoryStorage[TData]) Save ¶
Save persists the storage to permanent storage if the storage is not dirty, this function does nothing
type SavingFunc ¶
SavingFunc is a function that saves the storage to permanent storage
type StorableType ¶
type StorableType interface {
// StoreName the name in the users' storage, must be unique in a storage
// only used for set/get in the users data, not for persisting usage (save/load)
StoreName() string
}
StorableType is an interface that all types that can be stored must implement
type Storage ¶
type Storage[DataType StorableType] interface {
// Get retrieves a resource for a given user
Get(user string, out *DataType) error
// List retrieves all resources' StoreName() for a given user
List(user string) ([]string, error)
// Set sets a resource for a given user
Set(user string, in *DataType) error
// Update updates a resource for a given user, using the updateFn
// to ensure that the resource is updated atomically (CAS)
Update(user string, storeName string, updateFn func(org *DataType) (updated *DataType, err error)) error
// Delete deletes a resource for a given user
Delete(user string, storeName string) error
// IsDirty returns true if the storage has been modified since
IsDirty() bool
// Save persists the storage to permanent storage
Save(ctx context.Context) error
// Load loads the storage from permanent storage
Load(ctx context.Context) error
}
Storage is an interface that all storage implementations must implement
Click to show internal directories.
Click to hide internal directories.