blob

package
v0.8.4 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidKey = errors.New("invalid key")
)

Functions

func ValidateKey

func ValidateKey(key string) bool

Validate a key for S3 and local file system compatibility

Types

type AfterCopyObjectHook added in v0.6.1

type AfterCopyObjectHook func(req *CopyObjectParams, resp *CopyObjectResponse)

type AfterDeleteObjectHook added in v0.6.1

type AfterDeleteObjectHook func(req string, resp bool)

type AfterPutObjectHook added in v0.6.1

type AfterPutObjectHook func(req *PutObjectParams, resp *PutObjectResponse)

Hook function signatures

type BlobChangeCallback added in v0.6.1

type BlobChangeCallback func(key string, eventType BlobEventType)

BlobChangeCallback is the function signature for blob change callbacks

type BlobEventType added in v0.6.1

type BlobEventType uint8

BlobEventType represents the type of blob operation that occurred

const (
	BlobEventPut BlobEventType = 1 << iota
	BlobEventDelete
	BlobEventCopy
)

BlobEvent constants define the different types of blob operations that can trigger events.

type BlobIndex

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

BlobIndex provides access to the blob metadata stored in SQLite

func (*BlobIndex) Close

func (bi *BlobIndex) Close() error

Close releases resources used by the index

func (*BlobIndex) Count

func (bi *BlobIndex) Count() int

Count returns the number of blobs in the index

func (*BlobIndex) FilterAfterTime

func (bi *BlobIndex) FilterAfterTime(after time.Time) ([]*BlobInfo, error)

FilterAfterTime returns blobs modified after the given time (maintains backward compatibility)

func (*BlobIndex) FilterBeforeTime

func (bi *BlobIndex) FilterBeforeTime(before time.Time) ([]*BlobInfo, error)

FilterBeforeTime returns blobs modified before the given time

func (*BlobIndex) FilterByKeyGlob

func (bi *BlobIndex) FilterByKeyGlob(pattern string) ([]*BlobInfo, error)

FilterByKeyGlob returns blobs with keys matching the given SQL LIKE pattern

func (*BlobIndex) FilterByPrefix

func (bi *BlobIndex) FilterByPrefix(prefix string) ([]*BlobInfo, error)

func (*BlobIndex) FilterBySuffix

func (bi *BlobIndex) FilterBySuffix(suffix string) ([]*BlobInfo, error)

func (*BlobIndex) FilterByTime

func (bi *BlobIndex) FilterByTime(filter TimeFilter) ([]*BlobInfo, error)

FilterByTime returns blobs modified after the given time

func (*BlobIndex) Get

func (bi *BlobIndex) Get(key string) (*BlobInfo, bool)

Get retrieves blob info by key

func (*BlobIndex) Iter

func (bi *BlobIndex) Iter() iter.Seq[*BlobInfo]

Iter returns an iterator over all blobs in the index

func (*BlobIndex) List

func (bi *BlobIndex) List() ([]*BlobInfo, error)

List returns all blobs in the index

func (*BlobIndex) Remove

func (bi *BlobIndex) Remove(key string) error

Remove deletes a blob from the index

func (*BlobIndex) Set

func (bi *BlobIndex) Set(blob *BlobInfo) error

Set adds or updates a blob in the index

func (*BlobIndex) SetMany

func (bi *BlobIndex) SetMany(blobs []*BlobInfo) error

SetMany adds or updates multiple blobs in the index in a single transaction

type BlobInfo

type BlobInfo struct {
	Key          string `json:"key" db:"key"`
	ETag         string `json:"etag" db:"etag"`
	Size         int64  `json:"size" db:"size"`
	LastModified string `json:"lastModified" db:"last_modified"`
}

type BlobService

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

func NewBlobService

func NewBlobService(cfg *S3Config, db *sqlx.DB) (*BlobService, error)

func (*BlobService) Backend

func (b *BlobService) Backend() IBlobBackend

Backend returns the underlying blob backend instance

func (*BlobService) Index

func (b *BlobService) Index() IBlobIndex

Index returns the blob index

func (*BlobService) OnBlobChange added in v0.6.1

func (b *BlobService) OnBlobChange(callback BlobChangeCallback)

SetOnBlobChangeCallback sets the callback function for blob changes

func (*BlobService) Shutdown

func (b *BlobService) Shutdown(ctx context.Context) error

Shutdown releases any resources used by the service

func (*BlobService) Start

func (b *BlobService) Start(ctx context.Context) error

type CompleteMultipartUploadParams

type CompleteMultipartUploadParams struct {
	Key      string           `json:"key"`
	UploadID string           `json:"uploadId"`
	Parts    []*CompletedPart `json:"parts"`
}

type CompletedPart

type CompletedPart struct {
	PartNumber int    `json:"partNumber"`
	ETag       string `json:"etag"`
}

type CopyObjectParams

type CopyObjectParams struct {
	SourceKey      string
	DestinationKey string
}

type CopyObjectResponse

type CopyObjectResponse struct {
	ETag         string
	LastModified time.Time
}

type GetObjectResponse

type GetObjectResponse struct {
	Body         io.ReadCloser
	ETag         string
	Size         int64
	LastModified time.Time
}

type IBlobBackend added in v0.6.1

type IBlobBackend interface {
	// GetObject retrieves an object from storage by its key
	GetObject(ctx context.Context, key string) (*GetObjectResponse, error)

	// GetObjectPresigned generates a presigned URL for downloading an object
	GetObjectPresigned(ctx context.Context, key string) (string, error)

	// PutObject uploads a single object to storage
	PutObject(ctx context.Context, params *PutObjectParams) (*PutObjectResponse, error)

	// PutObjectPresigned generates a presigned URL for uploading an object
	PutObjectPresigned(ctx context.Context, key string) (string, error)

	// PutObjectMultipart initiates a multipart upload and returns upload URLs
	PutObjectMultipart(ctx context.Context, params *PutObjectMultipartParams) (*PutObjectMultipartResponse, error)

	// CompleteMultipartUpload finalizes a multipart upload
	CompleteMultipartUpload(ctx context.Context, params *CompleteMultipartUploadParams) (*PutObjectResponse, error)

	// CopyObject copies an object from one location to another
	CopyObject(ctx context.Context, params *CopyObjectParams) (*CopyObjectResponse, error)

	// DeleteObject removes an object from storage, returns true if successful
	DeleteObject(ctx context.Context, key string) (bool, error)

	// ListObjects returns a list of all objects in storage
	ListObjects(ctx context.Context) ([]*BlobInfo, error)

	// Delegate returns the underlying backend implementation
	Delegate() any
	// contains filtered or unexported methods
}

IBlobBackend defines the interface for blob storage backend operations. It provides methods for basic CRUD operations on blob objects including single-part uploads, multipart uploads, presigned URLs, and object management. The interface is designed to be implemented by different storage backends such as S3, local filesystem, or other cloud storage providers.

type IBlobIndex

type IBlobIndex interface {
	// Get retrieves a blob by its key, returning the blob info and whether it exists
	Get(key string) (*BlobInfo, bool)

	// Set stores a blob in the index, creating or updating the entry
	Set(blob *BlobInfo) error

	// SetMany stores multiple blobs in the index in a single operation
	SetMany(blobs []*BlobInfo) error

	// Remove deletes a blob from the index by its key
	Remove(key string) error

	// List returns all blobs in the index as a slice
	List() ([]*BlobInfo, error)

	// Iter returns an iterator for traversing all blobs in the index
	Iter() iter.Seq[*BlobInfo]

	// Count returns the total number of blobs in the index
	Count() int

	// FilterByKeyGlob filters blobs by key using glob pattern matching
	FilterByKeyGlob(pattern string) ([]*BlobInfo, error)

	// FilterByPrefix filters blobs by key prefix
	FilterByPrefix(prefix string) ([]*BlobInfo, error)

	// FilterBySuffix filters blobs by key suffix
	FilterBySuffix(suffix string) ([]*BlobInfo, error)

	// FilterByTime filters blobs based on a time range filter
	FilterByTime(filter TimeFilter) ([]*BlobInfo, error)

	// FilterAfterTime filters blobs modified after the specified time
	FilterAfterTime(after time.Time) ([]*BlobInfo, error)

	// FilterBeforeTime filters blobs modified before the specified time
	FilterBeforeTime(before time.Time) ([]*BlobInfo, error)
}

IBlobIndex defines the interface for blob index operations. It provides methods for managing and querying blob metadata in an index, including CRUD operations, filtering, and iteration capabilities. The interface is designed to be implemented by different index backends such as in-memory maps, databases, or other storage systems.

type PutObjectMultipartParams

type PutObjectMultipartParams struct {
	Key   string `json:"key" binding:"required"`
	Parts uint16 `json:"parts" binding:"required"`
}

type PutObjectMultipartResponse

type PutObjectMultipartResponse struct {
	Key      string   `json:"key"`
	UploadID string   `json:"uploadId"`
	URLs     []string `json:"urls"`
}

type PutObjectParams

type PutObjectParams struct {
	Key  string
	ETag string
	Size int64
	Body io.Reader
}

type PutObjectPresignedResponse

type PutObjectPresignedResponse struct {
	Name          string   `json:"name" binding:"required"`
	UploadID      string   `json:"uploadId"`
	PresignedURLs []string `json:"presignedUrls"`
}

type PutObjectResponse

type PutObjectResponse struct {
	Key          string
	Version      string
	ETag         string
	Size         int64
	LastModified time.Time
}

type S3Backend

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

func NewS3Backend

func NewS3Backend(s3Client *s3.Client, config *S3Config) *S3Backend

func NewS3BackendWithConfig

func NewS3BackendWithConfig(cfg *S3Config) *S3Backend

func (*S3Backend) CompleteMultipartUpload

func (s *S3Backend) CompleteMultipartUpload(ctx context.Context, params *CompleteMultipartUploadParams) (*PutObjectResponse, error)

func (*S3Backend) CopyObject

func (s *S3Backend) CopyObject(ctx context.Context, params *CopyObjectParams) (*CopyObjectResponse, error)

func (*S3Backend) Delegate

func (s *S3Backend) Delegate() any

func (*S3Backend) DeleteObject

func (s *S3Backend) DeleteObject(ctx context.Context, key string) (bool, error)

func (*S3Backend) GetObject

func (s *S3Backend) GetObject(ctx context.Context, key string) (*GetObjectResponse, error)

func (*S3Backend) GetObjectPresigned

func (s *S3Backend) GetObjectPresigned(ctx context.Context, key string) (string, error)

func (*S3Backend) ListObjects

func (s *S3Backend) ListObjects(ctx context.Context) ([]*BlobInfo, error)

func (*S3Backend) PutObject

func (s *S3Backend) PutObject(ctx context.Context, params *PutObjectParams) (*PutObjectResponse, error)

Add an object to a bucket

func (*S3Backend) PutObjectMultipart

func (s *S3Backend) PutObjectMultipart(ctx context.Context, params *PutObjectMultipartParams) (*PutObjectMultipartResponse, error)

func (*S3Backend) PutObjectPresigned

func (s *S3Backend) PutObjectPresigned(ctx context.Context, key string) (string, error)

type S3Config

type S3Config struct {
	BucketName    string `mapstructure:"bucket_name"`
	Region        string `mapstructure:"region"`
	AccessKey     string `mapstructure:"access_key"`
	SecretKey     string `mapstructure:"secret_key"`
	Endpoint      string `mapstructure:"endpoint"`
	UseAccelerate bool   `mapstructure:"use_accelerate"`
}

func (S3Config) LogValue

func (s3c S3Config) LogValue() slog.Value

func (*S3Config) Validate

func (c *S3Config) Validate() error

type Service added in v0.6.1

type Service interface {
	// Backend returns the underlying blob storage backend
	Backend() IBlobBackend

	// Index returns the blob index for metadata management
	Index() IBlobIndex

	// OnBlobChange registers a callback for blob change events
	OnBlobChange(callback BlobChangeCallback)
}

Service defines the minimal interface for blob operations. It provides access to the underlying backend storage, index management, and allows registering callbacks for blob change events.

type TimeFilter

type TimeFilter struct {
	Before *time.Time
	After  *time.Time
}

Jump to

Keyboard shortcuts

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