blobstore

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package blobstore provides content-addressed blob storage with metadata queries, tenant isolation, and TTL-based expiry. It demonstrates all plugin API patterns: host functions, HTTP routes, database migrations, and background workers.

Blobs are stored via a pluggable Backend interface. The memory backend stores bytes in the blob_content.data BYTEA column (dev/testing). The S3 backend stores bytes in S3-compatible object storage; only metadata is kept in PostgreSQL. Switch backends via the "backend" config option.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New() plugin.Plugin

New creates a new Plugin instance.

Types

type Backend

type Backend interface {
	// Put stores blob bytes addressed by the hex-encoded SHA-256 hash.
	Put(ctx context.Context, sha256 string, data []byte, contentType string) error
	// Get retrieves blob bytes by hex-encoded SHA-256 hash.
	Get(ctx context.Context, sha256 string) ([]byte, error)
	// Delete removes blob bytes by hex-encoded SHA-256 hash.
	Delete(ctx context.Context, sha256 string) error
}

Backend stores and retrieves blob bytes. Implementations must be safe for concurrent use.

type Config

type Config struct {
	Backend         string `json:"backend"`                     // "s3" or "memory"; defaults to "memory"
	Bucket          string `json:"bucket"`                      // S3 bucket name (for s3 backend)
	Region          string `json:"region"`                      // AWS region (for s3 backend)
	Endpoint        string `json:"endpoint,omitempty"`          // custom S3 endpoint (for MinIO/GCS)
	AccessKeyID     string `json:"access_key_id,omitempty"`     // S3 access key; falls back to env/instance profile
	SecretAccessKey string `json:"secret_access_key,omitempty"` // S3 secret key
	Secure          bool   `json:"secure"`                      // use HTTPS (default true, set false for local MinIO)
	MaxBlobSize     int64  `json:"max_blob_size"`               // max blob bytes; default 10 MB
}

Config controls blobstore backend selection and S3 parameters.

type Plugin

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

Plugin implements content-addressed blob storage with tenant isolation.

func (*Plugin) Info

func (p *Plugin) Info() plugin.PluginInfo

Info returns plugin metadata for discovery and documentation.

func (*Plugin) Init

func (p *Plugin) Init(ctx context.Context, env *plugin.Environment) error

Init initializes the plugin with the given environment. It parses optional configuration and sets safe defaults for dev/testing.

func (*Plugin) Migrations

func (p *Plugin) Migrations() []plugin.Migration

Migrations returns the database schema for blob storage. Tables are idempotent (IF NOT EXISTS) and safe to run multiple times.

func (*Plugin) RegisterHostFunctions

func (p *Plugin) RegisterHostFunctions(scope plugin.FuncRegistry) error

RegisterHostFunctions registers workflow-callable functions on the scoped function registry. The plugin name is implicit -- each plugin gets its own scope, so function names need not be globally unique.

func (*Plugin) RegisterRoutes

func (p *Plugin) RegisterRoutes(mux *http.ServeMux) error

func (*Plugin) Run

func (p *Plugin) Run(ctx context.Context) error

Run starts the TTL cleanup goroutine. It runs every hour, deleting expired blob_index entries and garbage-collecting blob_content rows whose ref_count reaches zero. Returns when ctx is cancelled.

Jump to

Keyboard shortcuts

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