blob

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2025 License: Apache-2.0 Imports: 18 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 BlobBackend

type BlobBackend interface {
	GetObject(ctx context.Context, key string) (*GetObjectResponse, error)
	GetObjectPresigned(ctx context.Context, key string) (string, error)
	PutObject(ctx context.Context, params *PutObjectParams) (*PutObjectResponse, error)
	PutObjectPresigned(ctx context.Context, key string) (string, error)
	PutObjectMultipart(ctx context.Context, params *PutObjectMultipartParams) (*PutObjectMultipartResponse, error)
	CompleteMultipartUpload(ctx context.Context, params *CompleteMultipartUploadParams) (*PutObjectResponse, error)
	CopyObject(ctx context.Context, params *CopyObjectParams) (*CopyObjectResponse, error)
	DeleteObject(ctx context.Context, key string) (bool, error)
	ListObjects(ctx context.Context) ([]*BlobInfo, error)
	Delegate() any
	// contains filtered or unexported methods
}

not enforced yet

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() BlobBackend

Backend returns the underlying blob backend instance

func (*BlobService) Index

func (b *BlobService) Index() *BlobIndex

Index returns the blob index

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 IBlobIndex

type IBlobIndex interface {
	Get(key string) (*BlobInfo, bool)
	Set(blob *BlobInfo) error
	SetMany(blobs []*BlobInfo) error
	Remove(key string) error
	List() ([]*BlobInfo, error)
	Iter() iter.Seq[*BlobInfo]
	Count() int
	FilterByKeyGlob(pattern string) ([]*BlobInfo, error)
	FilterByPrefix(prefix string) ([]*BlobInfo, error)
	FilterBySuffix(suffix string) ([]*BlobInfo, error)
	FilterByTime(filter TimeFilter) ([]*BlobInfo, error)
	FilterAfterTime(after time.Time) ([]*BlobInfo, error)
	FilterBeforeTime(before time.Time) ([]*BlobInfo, error)
}

not enforced yet

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 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