Documentation
¶
Overview ¶
Package storage provides OPTIONAL infrastructure adapters for persistent key-value storage (file-based or SQLite database).
This package is NOT required for core data transformation functionality. It is provided as a convenience for applications that need simple storage alongside their transformation pipelines. Most teams already have their own storage layer — use this only if it fits your needs.
pkg/adapter/storage/factory.go
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewStorage ¶
func NewStorage(config *Config) (port.StoragePort, error)
NewStorage creates a new storage adapter based on configuration. This is the factory method that implements the hexagonal architecture pattern.
Architecture Note: This factory is part of the adapter layer and creates SECONDARY ADAPTERS that implement the StoragePort interface. The domain layer depends ONLY on the port interface, never on concrete implementations.
Example:
config := &storage.Config{
Type: storage.StorageTypeFile,
FileConfig: &storage.FileConfig{
BaseDir: "/var/lib/morpheus/storage",
},
}
storage, err := storage.NewStorage(config)
if err != nil {
log.Fatal(err)
}
// Use storage via port.StoragePort interface
err = storage.Save(ctx, "key", data)
Types ¶
type Config ¶
type Config struct {
// Type specifies which storage backend to use
Type StorageType
// FileConfig is used when Type == StorageTypeFile
FileConfig *FileConfig
// DatabaseConfig is used when Type == StorageTypeDatabase
DatabaseConfig *DatabaseConfig
}
Config holds configuration for storage adapters
type DatabaseConfig ¶
type DatabaseConfig struct {
// Driver specifies the database driver (postgres, mysql, sqlite)
Driver string
// DSN is the data source name (connection string)
DSN string
// MaxConnections is the maximum number of database connections
MaxConnections int
// MaxIdleConnections is the maximum number of idle connections
MaxIdleConnections int
}
DatabaseConfig holds database storage configuration
type FileConfig ¶
type FileConfig struct {
// BaseDir is the root directory for file storage
BaseDir string
}
FileConfig holds file storage configuration
type StorageType ¶
type StorageType string
StorageType represents the type of storage backend
const ( // StorageTypeFile uses file system storage StorageTypeFile StorageType = "file" // StorageTypeDatabase uses database storage (SQLite) StorageTypeDatabase StorageType = "database" // StorageTypeMemory uses in-memory storage (for testing) StorageTypeMemory StorageType = "memory" )
Directories
¶
| Path | Synopsis |
|---|---|
|
Package database provides a SQLite-backed key-value storage adapter.
|
Package database provides a SQLite-backed key-value storage adapter. |
|
Package file provides a file system-backed key-value storage adapter.
|
Package file provides a file system-backed key-value storage adapter. |