blobstore

package
v0.19.783 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BlobWriteEnabledKey blobContextKey = "blob_write_enabled"
	BlobAutoLoadKey     blobContextKey = "blob_auto_load"
	BlobServiceKey      blobContextKey = "blob_service"
)

Variables

This section is empty.

Functions

func IsBlobAutoLoad

func IsBlobAutoLoad(ctx context.Context) bool

IsBlobAutoLoad checks if auto-load is enabled (default: false)

func IsBlobWriteEnabled

func IsBlobWriteEnabled(ctx context.Context) bool

IsBlobWriteEnabled checks if blob writes are enabled (default: true)

func WithBlobAutoLoad

func WithBlobAutoLoad(ctx context.Context, enabled bool) context.Context

WithBlobAutoLoad controls whether blobs auto-load from S3 on query

func WithBlobService

func WithBlobService(ctx context.Context, svc Service) context.Context

WithBlobService sets the blobstore service in context

func WithBlobWriteEnabled

func WithBlobWriteEnabled(ctx context.Context, enabled bool) context.Context

WithBlobWriteEnabled controls whether blobs upload to S3 on save

Types

type Blob

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

Blob is a GORM custom type that stores large strings in S3 The database column stores JSONB metadata including the S3 key The actual content is stored in S3 at: {org_id}/{owner_type}/{owner_id}/{blob_id}

func (*Blob) AfterFind

func (b *Blob) AfterFind(tx *gorm.DB) error

AfterFind implements GORM hook for automatic S3 download

func (*Blob) BeforeSave

func (b *Blob) BeforeSave(tx *gorm.DB) error

BeforeSave implements GORM hook for automatic S3 upload

func (*Blob) BlobID

func (b *Blob) BlobID() string

BlobID returns the S3 key (blob ID)

func (*Blob) Get

func (b *Blob) Get(ctx context.Context) (string, error)

Get returns the blob value, loading from S3 if needed

func (Blob) GormDataType

func (b Blob) GormDataType() string

GormDataType returns the database column type

func (*Blob) IsSet

func (b *Blob) IsSet() bool

IsSet returns whether the blob has a value (either loaded or with blob ID)

func (*Blob) Metadata

func (b *Blob) Metadata() BlobMetadata

Metadata returns the blob metadata

func (*Blob) Scan

func (b *Blob) Scan(value interface{}) error

Scan implements database/sql.Scanner Reads the blob metadata from database (JSONB column)

func (*Blob) Set

func (b *Blob) Set(value string)

Set sets the blob value and marks it dirty for upload

func (*Blob) SetContentType

func (b *Blob) SetContentType(contentType string)

SetContentType sets the content type for the blob

func (*Blob) String

func (b *Blob) String() string

String returns the blob value if loaded, or empty string Warning: Does not load from S3 if not already loaded

func (*Blob) Value

func (b *Blob) Value() (driver.Value, error)

Value implements driver.Valuer Returns the blob metadata as JSONB to store in database

type BlobMetadata

type BlobMetadata struct {
	BlobID      string `json:"blob_id"`                // S3 key (blob_id)
	S3Key       string `json:"s3_key"`                 // Full S3 path: org_id/blob_id
	Size        int64  `json:"size,omitempty"`         // Size in bytes
	ContentType string `json:"content_type,omitempty"` // MIME type
	Checksum    string `json:"checksum,omitempty"`     // SHA256 checksum
	CreatedBy   string `json:"created_by,omitempty"`   // Account ID who created the blob
	CreatedAt   string `json:"created_at,omitempty"`   // ISO 8601 timestamp
}

BlobMetadata represents the JSONB structure stored in the database

type Service

type Service interface {
	// Upload stores blob data in S3 (byte-based, for small payloads)
	Upload(ctx context.Context, s3Key string, data []byte) error

	// Download retrieves blob data from S3 (byte-based, for small payloads)
	Download(ctx context.Context, s3Key string) ([]byte, error)

	// UploadStream stores blob data in S3 (streaming, for large payloads)
	// Returns SHA256 checksum
	UploadStream(ctx context.Context, s3Key string, reader io.Reader) (checksum string, err error)

	// DownloadStream retrieves blob data from S3 (streaming, for large payloads)
	// Returns io.ReadCloser that must be closed by caller
	DownloadStream(ctx context.Context, s3Key string) (io.ReadCloser, error)

	// GetMetadata retrieves blob metadata without downloading content
	GetMetadata(ctx context.Context, s3Key string) (size int64, contentType string, err error)
}

Service provides blob storage operations with S3

func GetBlobService

func GetBlobService(ctx context.Context) Service

GetBlobService retrieves the blobstore service from context

func NewService

func NewService(cfg *internal.Config) (Service, error)

NewService creates a new blob storage service

Jump to

Keyboard shortcuts

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