Documentation
¶
Overview ¶
Package storage is the flat-file JSON store. Per-resource locks coordinate goroutines while advisory file locks make read-modify-write safe across processes.
Index ¶
- func ReadAs[T any](s *Store, key []string) (T, error)
- func UpdateAs[T any](s *Store, key []string, mutate func(*T)) (T, error)
- type NotFoundError
- type Option
- type Store
- func (s *Store) CreateExclusive(key []string, content any) (bool, error)
- func (s *Store) List(prefix []string) ([][]string, error)
- func (s *Store) Read(key []string) (any, error)
- func (s *Store) ReadInto(key []string, dst any) error
- func (s *Store) Remove(key []string) error
- func (s *Store) Update(key []string, mutate func(any)) (any, error)
- func (s *Store) Write(key []string, content any) error
- func (s *Store) WriteBatch(items []WriteItem) error
- type WriteItem
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type NotFoundError ¶
type NotFoundError struct {
Message string `json:"message"`
}
NotFoundError is the model-visible storage miss.
func (*NotFoundError) Error ¶
func (e *NotFoundError) Error() string
type Store ¶
type Store struct {
Dir string
// contains filtered or unexported fields
}
Store is a JSON store rooted at Dir.
func NewFromDataDir ¶
NewFromDataDir roots the store at dataDir/storage.
func (*Store) CreateExclusive ¶
CreateExclusive writes a resource only when no claimant has created it. The store-wide advisory lock makes the check/atomic-rename indivisible across cooperating processes; the returned boolean reports the winner.
func (*Store) Update ¶
Update holds the resource mutex and cross-process flock across read, mutation, and rewrite. mutate must not call a Store method for the same key: the callback is deliberately non-reentrant and doing so will deadlock.
func (*Store) WriteBatch ¶
WriteBatch serializes a related group under ordered per-resource locks. Callers control item order; prompt persistence writes parts before the message that makes the turn visible. Files are synced individually, then each touched directory is synced once after all renames.