Documentation
¶
Overview ¶
Package file provides a file system-backed key-value storage adapter.
pkg/adapter/storage/file/storage.go
Index ¶
- Variables
- type Storage
- func (s *Storage) Close() error
- func (s *Storage) Delete(ctx context.Context, key string) error
- func (s *Storage) List(ctx context.Context, prefix string) ([]string, error)
- func (s *Storage) Load(ctx context.Context, key string) (any, error)
- func (s *Storage) Save(ctx context.Context, key string, data any) error
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound indicates the requested key doesn't exist ErrNotFound = errors.New("key not found") // ErrInvalidKey indicates the key is empty or contains invalid characters ErrInvalidKey = errors.New("invalid key") )
Functions ¶
This section is empty.
Types ¶
type Storage ¶
type Storage struct {
// contains filtered or unexported fields
}
Storage implements port.StoragePort using file system storage. It provides atomic write operations using temp file + rename pattern.
Architecture: Secondary Adapter (implements domain port) - Depends on: domain/port.StoragePort interface (dependency inversion) - Used by: DLQ, Tokenizer, AuditLogger - Pure infrastructure concern (no business logic)
func NewStorage ¶
NewStorage creates a new file-based storage adapter. The baseDir will be created if it doesn't exist.
Example:
storage, err := file.NewStorage("/var/lib/morpheus/storage")
if err != nil {
log.Fatal(err)
}
Architecture Note: This is a SECONDARY ADAPTER that implements the StoragePort interface. It has NO knowledge of the domain layer - it simply provides file storage.
func (*Storage) Close ¶
Close performs any cleanup operations. Currently a no-op for file storage, but included for interface compatibility.
func (*Storage) Delete ¶
Delete removes the file associated with the key. Returns ErrNotFound if the key doesn't exist.
Example:
err := storage.Delete(ctx, "job-123")
func (*Storage) List ¶
List returns all keys with the given prefix. Useful for querying stored items (e.g., all failed jobs).
Example:
keys, err := storage.List(ctx, "dlq/") // Returns: ["dlq/job-1", "dlq/job-2", ...]
func (*Storage) Load ¶
Load retrieves data from file and unmarshals it. Returns ErrNotFound if the key doesn't exist.
Example:
var job entity.Job
data, err := storage.Load(ctx, "job-123")
if err == file.ErrNotFound {
// Handle missing key
}
json.Unmarshal(data.([]byte), &job)