storage

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

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

type BackendConstructor func(config map[string]interface{}) (Backend, error)

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

func NewConfigFromEnv(db *sql.DB) *Config

NewConfigFromEnv creates configuration from environment variables

func (*Config) CreateBackend

func (c *Config) CreateBackend() (Backend, error)

CreateBackend creates a storage backend based on configuration

func (*Config) Validate

func (c *Config) Validate() error

Validate checks if the configuration is valid

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

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

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

Migrate moves content to another backend

func (*FilesystemBackend) Retrieve

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

Migrate moves content to target backend

func (*MixedModeBackend) Retrieve

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL