Help us shape the future of Go! Take the 2026 Go Developer Survey

storage

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AttachmentMetadata

type AttachmentMetadata struct {
	ID         string    // Unique identifier (UUID)
	Name       string    // Original filename
	MimeType   string    // MIME type
	Size       int64     // Size in bytes
	StorageKey string    // Storage backend key
	StorageURI string    // Full URI for retrieval
	UploadedAt time.Time // Upload timestamp
}

AttachmentMetadata contains metadata about a stored attachment

type Config

type Config struct {
	Driver string // "local", "s3", "gcs", "minio"

	// Local filesystem config
	LocalBasePath string // e.g., "/data/artifacts"
	LocalBaseURL  string // e.g., "http://localhost:8080/attachments"

	// S3-compatible config
	S3Endpoint        string // AWS endpoint or MinIO URL
	S3Region          string // AWS region
	S3Bucket          string // Bucket name
	S3AccessKeyID     string
	S3SecretAccessKey string
	S3UsePathStyle    bool   // For MinIO compatibility
	S3PublicURL       string // Base URL for public access (optional)
}

Config holds storage driver configuration

type Driver

type Driver interface {
	// Upload stores an attachment and returns metadata
	Upload(ctx context.Context, name, mimeType string, content io.Reader) (*AttachmentMetadata, error)

	// Download retrieves an attachment by storage key
	Download(ctx context.Context, storageKey string) (io.ReadCloser, error)

	// GetMetadata retrieves metadata for an attachment
	GetMetadata(ctx context.Context, storageKey string) (*AttachmentMetadata, error)

	// Delete removes an attachment (for cleanup)
	Delete(ctx context.Context, storageKey string) error

	// GetSignedURL generates a time-limited direct access URL (for cloud storage)
	GetSignedURL(ctx context.Context, storageKey string, expiration time.Duration) (string, error)

	// Name returns the driver name (e.g., "local", "s3")
	Name() string

	// Close cleans up resources
	Close() error
}

Driver defines the interface for attachment storage backends

func NewDriver

func NewDriver(cfg Config, logger *slog.Logger) (Driver, error)

NewDriver creates a storage driver based on configuration

func NewDriverFromEnv

func NewDriverFromEnv(logger *slog.Logger) (Driver, error)

NewDriverFromEnv creates a driver from environment variables

type LocalDriver

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

LocalDriver implements storage.Driver for local filesystem storage

func NewLocalDriver

func NewLocalDriver(cfg Config, logger *slog.Logger) (*LocalDriver, error)

NewLocalDriver creates a new local filesystem storage driver

func (*LocalDriver) Close

func (d *LocalDriver) Close() error

Close cleans up resources (no-op for local driver)

func (*LocalDriver) Delete

func (d *LocalDriver) Delete(ctx context.Context, storageKey string) error

Delete removes an attachment from the local filesystem

func (*LocalDriver) Download

func (d *LocalDriver) Download(ctx context.Context, storageKey string) (io.ReadCloser, error)

Download retrieves an attachment from the local filesystem

func (*LocalDriver) GetMetadata

func (d *LocalDriver) GetMetadata(ctx context.Context, storageKey string) (*AttachmentMetadata, error)

GetMetadata retrieves metadata for an attachment

func (*LocalDriver) GetSignedURL

func (d *LocalDriver) GetSignedURL(ctx context.Context, storageKey string, expiration time.Duration) (string, error)

GetSignedURL is not supported for local storage (returns the public URL)

func (*LocalDriver) Name

func (d *LocalDriver) Name() string

Name returns the driver name

func (*LocalDriver) Upload

func (d *LocalDriver) Upload(ctx context.Context, name, mimeType string, content io.Reader) (*AttachmentMetadata, error)

Upload stores an attachment to the local filesystem

type S3Driver

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

S3Driver implements storage.Driver for S3-compatible storage

func NewS3Driver

func NewS3Driver(cfg Config, logger *slog.Logger) (*S3Driver, error)

NewS3Driver creates a new S3 storage driver

func (*S3Driver) Close

func (d *S3Driver) Close() error

Close cleans up resources (no-op for S3 driver)

func (*S3Driver) Delete

func (d *S3Driver) Delete(ctx context.Context, storageKey string) error

Delete removes an attachment from S3

func (*S3Driver) Download

func (d *S3Driver) Download(ctx context.Context, storageKey string) (io.ReadCloser, error)

Download retrieves an attachment from S3

func (*S3Driver) GetMetadata

func (d *S3Driver) GetMetadata(ctx context.Context, storageKey string) (*AttachmentMetadata, error)

GetMetadata retrieves metadata for an attachment from S3

func (*S3Driver) GetSignedURL

func (d *S3Driver) GetSignedURL(ctx context.Context, storageKey string, expiration time.Duration) (string, error)

GetSignedURL generates a time-limited presigned URL for S3 object access

func (*S3Driver) Name

func (d *S3Driver) Name() string

Name returns the driver name

func (*S3Driver) Upload

func (d *S3Driver) Upload(ctx context.Context, name, mimeType string, content io.Reader) (*AttachmentMetadata, error)

Upload stores an attachment to S3

Jump to

Keyboard shortcuts

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