storage

package
v0.4.4 Latest Latest
Warning

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

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

Documentation

Overview

Package storage provides factory functions for creating storage-dependent components. It implements the Abstract Factory pattern to ensure related components (state service, sync writer, registry service) are created with compatible storage backends.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DatabaseFactory

type DatabaseFactory struct {
	// contains filtered or unexported fields
}

DatabaseFactory creates database-backed storage components. All components created by this factory use PostgreSQL for persistence.

func NewDatabaseFactory

func NewDatabaseFactory(ctx context.Context, cfg *config.Config) (*DatabaseFactory, error)

NewDatabaseFactory creates a new database-backed storage factory. It establishes a connection pool to the configured PostgreSQL database.

func (*DatabaseFactory) Cleanup

func (d *DatabaseFactory) Cleanup()

Cleanup releases resources held by the database factory. This closes the database connection pool and any active connections.

func (*DatabaseFactory) CreateRegistryService

func (d *DatabaseFactory) CreateRegistryService(ctx context.Context) (service.RegistryService, error)

CreateRegistryService creates a database-backed registry service. The service reads and writes registry data directly to PostgreSQL.

func (*DatabaseFactory) CreateStateService

func (d *DatabaseFactory) CreateStateService(_ context.Context) (state.RegistryStateService, error)

CreateStateService creates a database-backed state service for sync status tracking.

func (*DatabaseFactory) CreateSyncWriter

func (d *DatabaseFactory) CreateSyncWriter(_ context.Context) (writer.SyncWriter, error)

CreateSyncWriter creates a database-backed sync writer for storing registry data.

type Factory

type Factory interface {
	// CreateStateService creates a state service for sync status tracking.
	// The returned service uses storage appropriate for this factory's type
	// (file-based or database-backed).
	CreateStateService(ctx context.Context) (state.RegistryStateService, error)

	// CreateSyncWriter creates a writer for storing synced registry data.
	// The returned writer uses storage appropriate for this factory's type.
	CreateSyncWriter(ctx context.Context) (writer.SyncWriter, error)

	// CreateRegistryService creates the main registry service.
	// The returned service uses storage appropriate for this factory's type.
	CreateRegistryService(ctx context.Context) (service.RegistryService, error)

	// Cleanup releases any resources held by this factory.
	// For database factories, this closes the connection pool.
	// For file factories, this is a no-op.
	// Should be called when the application shuts down.
	Cleanup()
}

Factory creates storage-dependent components as a family. Implementations ensure all components are compatible with each other (e.g., all use database or all use file storage).

The factory encapsulates the creation of: - RegistryStateService: Tracks sync status - SyncWriter: Writes synced registry data - RegistryService: Serves registry API requests

It also manages the lifecycle of storage resources (e.g., database connections).

func NewStorageFactory

func NewStorageFactory(ctx context.Context, cfg *config.Config, dataDir string) (Factory, error)

NewStorageFactory creates a storage factory based on the configured storage type. Returns a FileFactory for file-based storage or a DatabaseFactory for database storage.

type FileFactory

type FileFactory struct {
	// contains filtered or unexported fields
}

FileFactory creates file-based storage components. All components created by this factory use the local filesystem for persistence.

func NewFileFactory

func NewFileFactory(cfg *config.Config, dataDir string) (*FileFactory, error)

NewFileFactory creates a new file-based storage factory. It initializes the file storage manager and status persistence, ensuring the necessary directories exist.

func (*FileFactory) Cleanup

func (*FileFactory) Cleanup()

Cleanup releases resources held by the file factory. For file storage, there are no resources to clean up (no connection pools, etc.).

func (*FileFactory) CreateRegistryService

func (f *FileFactory) CreateRegistryService(ctx context.Context) (service.RegistryService, error)

CreateRegistryService creates a file-based registry service. The service reads registry data from files via the storage manager.

func (*FileFactory) CreateStateService

func (f *FileFactory) CreateStateService(_ context.Context) (state.RegistryStateService, error)

CreateStateService creates a file-based state service for sync status tracking.

func (*FileFactory) CreateSyncWriter

func (f *FileFactory) CreateSyncWriter(_ context.Context) (writer.SyncWriter, error)

CreateSyncWriter creates a file-based sync writer for storing registry data.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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