Documentation
¶
Overview ¶
Package storage provides article attachment storage backends.
Index ¶
- type ArticleContent
- type Backend
- type BackendConstructor
- type BackendInfo
- type BackendStats
- type Config
- type DatabaseBackend
- func (d *DatabaseBackend) Delete(ctx context.Context, ref *StorageReference) error
- func (d *DatabaseBackend) Exists(ctx context.Context, ref *StorageReference) (bool, error)
- func (d *DatabaseBackend) GetInfo() *BackendInfo
- func (d *DatabaseBackend) HealthCheck(ctx context.Context) error
- func (d *DatabaseBackend) List(ctx context.Context, articleID int64) ([]*StorageReference, error)
- func (d *DatabaseBackend) Migrate(ctx context.Context, ref *StorageReference, target Backend) (*StorageReference, error)
- func (d *DatabaseBackend) Retrieve(ctx context.Context, ref *StorageReference) (*ArticleContent, error)
- func (d *DatabaseBackend) Store(ctx context.Context, articleID int64, content *ArticleContent) (*StorageReference, error)
- type Factory
- type FilesystemBackend
- func (f *FilesystemBackend) Delete(ctx context.Context, ref *StorageReference) error
- func (f *FilesystemBackend) Exists(ctx context.Context, ref *StorageReference) (bool, error)
- func (f *FilesystemBackend) GetInfo() *BackendInfo
- func (f *FilesystemBackend) HealthCheck(ctx context.Context) error
- func (f *FilesystemBackend) List(ctx context.Context, articleID int64) ([]*StorageReference, error)
- func (f *FilesystemBackend) Migrate(ctx context.Context, ref *StorageReference, target Backend) (*StorageReference, error)
- func (f *FilesystemBackend) Retrieve(ctx context.Context, ref *StorageReference) (*ArticleContent, error)
- func (f *FilesystemBackend) Store(ctx context.Context, articleID int64, content *ArticleContent) (*StorageReference, error)
- type MixedModeBackend
- func (m *MixedModeBackend) Delete(ctx context.Context, ref *StorageReference) error
- func (m *MixedModeBackend) Exists(ctx context.Context, ref *StorageReference) (bool, error)
- func (m *MixedModeBackend) GetInfo() *BackendInfo
- func (m *MixedModeBackend) HealthCheck(ctx context.Context) error
- func (m *MixedModeBackend) List(ctx context.Context, articleID int64) ([]*StorageReference, error)
- func (m *MixedModeBackend) Migrate(ctx context.Context, ref *StorageReference, target Backend) (*StorageReference, error)
- func (m *MixedModeBackend) Retrieve(ctx context.Context, ref *StorageReference) (*ArticleContent, error)
- func (m *MixedModeBackend) Store(ctx context.Context, articleID int64, content *ArticleContent) (*StorageReference, error)
- type StorageFactory
- type StorageReference
- type StreamingBackend
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ArticleContent ¶
type ArticleContent struct {
ArticleID int64
ContentType string
FileName string
FileSize int64
Content []byte
Metadata map[string]string
CreatedTime time.Time
CreatedBy int
}
ArticleContent represents the content to be stored.
type Backend ¶
type Backend interface {
// Store saves article content and returns a storage reference
Store(ctx context.Context, articleID int64, content *ArticleContent) (*StorageReference, error)
// Retrieve gets article content by reference
Retrieve(ctx context.Context, ref *StorageReference) (*ArticleContent, error)
// Delete removes article content
Delete(ctx context.Context, ref *StorageReference) error
// Exists checks if article content exists
Exists(ctx context.Context, ref *StorageReference) (bool, error)
// List returns all storage references for an article
List(ctx context.Context, articleID int64) ([]*StorageReference, error)
// Migrate moves content between backends
Migrate(ctx context.Context, ref *StorageReference, target Backend) (*StorageReference, error)
// GetInfo returns backend information
GetInfo() *BackendInfo
// HealthCheck verifies backend is operational
HealthCheck(ctx context.Context) error
}
Backend defines the interface for article storage backends.
type BackendConstructor ¶
BackendConstructor creates a new backend instance.
type BackendInfo ¶
type BackendInfo struct {
Name string
Type string
Capabilities []string
Status string
Statistics *BackendStats
}
BackendInfo provides information about a storage backend.
type BackendStats ¶
type BackendStats struct {
TotalFiles int64
TotalSize int64
FreeSpace int64
ReadLatency time.Duration
WriteLatency time.Duration
}
BackendStats contains usage statistics.
type Config ¶
type Config struct {
// Backend type: "DB" or "FS"
Backend string
// Filesystem backend settings
FSBasePath string
// Mixed mode settings
CheckAllBackends bool
// Migration settings
MigrationBatchSize int
MigrationSleepMs int
// Database connection (for both backends)
DB *sql.DB
}
Config represents storage configuration.
func NewConfigFromEnv ¶
NewConfigFromEnv creates configuration from environment variables.
func (*Config) CreateBackend ¶
CreateBackend creates a storage backend based on configuration.
type DatabaseBackend ¶
type DatabaseBackend struct {
// contains filtered or unexported fields
}
DatabaseBackend implements article storage in the database (OTRS ArticleStorageDB).
func NewDatabaseBackend ¶
func NewDatabaseBackend(db *sql.DB) *DatabaseBackend
NewDatabaseBackend creates a new database storage backend.
func (*DatabaseBackend) Delete ¶
func (d *DatabaseBackend) Delete(ctx context.Context, ref *StorageReference) error
Delete removes article content from the database.
func (*DatabaseBackend) Exists ¶
func (d *DatabaseBackend) Exists(ctx context.Context, ref *StorageReference) (bool, error)
Exists checks if article content exists in the database.
func (*DatabaseBackend) GetInfo ¶
func (d *DatabaseBackend) GetInfo() *BackendInfo
GetInfo returns backend information.
func (*DatabaseBackend) HealthCheck ¶
func (d *DatabaseBackend) HealthCheck(ctx context.Context) error
HealthCheck verifies the database connection.
func (*DatabaseBackend) List ¶
func (d *DatabaseBackend) List(ctx context.Context, articleID int64) ([]*StorageReference, error)
List returns all storage references for an article.
func (*DatabaseBackend) Migrate ¶
func (d *DatabaseBackend) Migrate(ctx context.Context, ref *StorageReference, target Backend) (*StorageReference, error)
Migrate is handled by the MixedModeBackend.
func (*DatabaseBackend) Retrieve ¶
func (d *DatabaseBackend) Retrieve(ctx context.Context, ref *StorageReference) (*ArticleContent, error)
Retrieve gets article content from the database.
func (*DatabaseBackend) Store ¶
func (d *DatabaseBackend) Store(ctx context.Context, articleID int64, content *ArticleContent) (*StorageReference, error)
Store saves article content to the database.
type Factory ¶
type Factory interface {
// Create instantiates a storage backend
Create(backendType string, config map[string]interface{}) (Backend, error)
// Register adds a new backend type
Register(backendType string, constructor BackendConstructor)
// List returns available backend types
List() []string
}
Factory creates storage backends based on configuration.
var DefaultFactory Factory = NewStorageFactory()
DefaultFactory is the global storage backend factory.
type FilesystemBackend ¶
type FilesystemBackend struct {
// contains filtered or unexported fields
}
FilesystemBackend implements article storage on the filesystem (OTRS ArticleStorageFS).
func NewFilesystemBackend ¶
func NewFilesystemBackend(basePath string, db *sql.DB) (*FilesystemBackend, error)
NewFilesystemBackend creates a new filesystem storage backend.
func (*FilesystemBackend) Delete ¶
func (f *FilesystemBackend) Delete(ctx context.Context, ref *StorageReference) error
Delete removes article content from the filesystem.
func (*FilesystemBackend) Exists ¶
func (f *FilesystemBackend) Exists(ctx context.Context, ref *StorageReference) (bool, error)
Exists checks if article content exists on the filesystem.
func (*FilesystemBackend) GetInfo ¶
func (f *FilesystemBackend) GetInfo() *BackendInfo
GetInfo returns backend information.
func (*FilesystemBackend) HealthCheck ¶
func (f *FilesystemBackend) HealthCheck(ctx context.Context) error
HealthCheck verifies the filesystem is accessible.
func (*FilesystemBackend) List ¶
func (f *FilesystemBackend) List(ctx context.Context, articleID int64) ([]*StorageReference, error)
List returns all storage references for an article.
func (*FilesystemBackend) Migrate ¶
func (f *FilesystemBackend) Migrate(ctx context.Context, ref *StorageReference, target Backend) (*StorageReference, error)
Migrate moves content to another backend.
func (*FilesystemBackend) Retrieve ¶
func (f *FilesystemBackend) Retrieve(ctx context.Context, ref *StorageReference) (*ArticleContent, error)
Retrieve gets article content from the filesystem.
func (*FilesystemBackend) Store ¶
func (f *FilesystemBackend) Store(ctx context.Context, articleID int64, content *ArticleContent) (*StorageReference, error)
Store saves article content to the filesystem.
type MixedModeBackend ¶
type MixedModeBackend struct {
// contains filtered or unexported fields
}
MixedModeBackend supports reading from multiple backends.
func NewMixedModeBackend ¶
func NewMixedModeBackend(primary Backend, fallbacks ...Backend) *MixedModeBackend
NewMixedModeBackend creates a backend that checks multiple storage locations.
func (*MixedModeBackend) Delete ¶
func (m *MixedModeBackend) Delete(ctx context.Context, ref *StorageReference) error
Delete removes from all backends.
func (*MixedModeBackend) Exists ¶
func (m *MixedModeBackend) Exists(ctx context.Context, ref *StorageReference) (bool, error)
Exists checks all backends.
func (*MixedModeBackend) GetInfo ¶
func (m *MixedModeBackend) GetInfo() *BackendInfo
GetInfo returns mixed mode backend information.
func (*MixedModeBackend) HealthCheck ¶
func (m *MixedModeBackend) HealthCheck(ctx context.Context) error
HealthCheck verifies all backends are operational.
func (*MixedModeBackend) List ¶
func (m *MixedModeBackend) List(ctx context.Context, articleID int64) ([]*StorageReference, error)
List combines results from all backends.
func (*MixedModeBackend) Migrate ¶
func (m *MixedModeBackend) Migrate(ctx context.Context, ref *StorageReference, target Backend) (*StorageReference, error)
Migrate moves content to target backend.
func (*MixedModeBackend) Retrieve ¶
func (m *MixedModeBackend) Retrieve(ctx context.Context, ref *StorageReference) (*ArticleContent, error)
Retrieve tries primary first, then fallbacks.
func (*MixedModeBackend) Store ¶
func (m *MixedModeBackend) Store(ctx context.Context, articleID int64, content *ArticleContent) (*StorageReference, error)
Store saves to the primary backend.
type StorageFactory ¶
type StorageFactory struct {
// contains filtered or unexported fields
}
StorageFactory implements the Factory interface.
func NewStorageFactory ¶
func NewStorageFactory() *StorageFactory
NewStorageFactory creates a new storage factory.
func (*StorageFactory) Create ¶
func (f *StorageFactory) Create(backendType string, config map[string]interface{}) (Backend, error)
Create instantiates a storage backend.
func (*StorageFactory) List ¶
func (f *StorageFactory) List() []string
List returns available backend types.
func (*StorageFactory) Register ¶
func (f *StorageFactory) Register(backendType string, constructor BackendConstructor)
Register adds a new backend type.
type StorageReference ¶
type StorageReference struct {
ID int64
ArticleID int64
Backend string
Location string
ContentType string
FileName string
FileSize int64
Checksum string
CreatedTime time.Time
AccessedTime time.Time
}
StorageReference points to stored content.
type StreamingBackend ¶
type StreamingBackend interface {
Backend
// StoreStream saves content from a reader
StoreStream(ctx context.Context, articleID int64, reader io.Reader, metadata *ArticleContent) (*StorageReference, error)
// RetrieveStream gets content as a reader
RetrieveStream(ctx context.Context, ref *StorageReference) (io.ReadCloser, error)
}
StreamingBackend extends Backend with streaming capabilities.