Documentation
¶
Overview ¶
Package store provides a generic, typed key-value storage layer used by workflow tasks to persist and retrieve intermediate data.
The two main interfaces are:
RawStore — byte-level storage with Upload, Download, Delete, Exists, and List operations. Concrete implementations include LocalStore (filesystem) and S3Store (S3-compatible object storage).
Store — a typed wrapper around RawStore that uses a Codec to serialize and deserialize Go values of any type T. JSONCodec is the default codec.
Keys are built with the KeyBuilder helper to ensure consistent, hierarchical naming across stores. The InstrumentedStore decorator adds OpenTelemetry tracing and metrics to any RawStore implementation.
Index ¶
- Constants
- func ArchiveDirectory(sourceDir string, writer io.Writer) (err error)
- func DeletePrefix(ctx context.Context, raw RawStore, prefix string) error
- func DownloadFile(ctx context.Context, raw RawStore, key, destPath, typ string) (err error)
- func ExtractArchive(reader io.Reader, destDir string) error
- func UploadFile(ctx context.Context, raw RawStore, key, sourcePath, typ string) error
- type BytesCodec
- type Codec
- type InstrumentedStore
- func (s *InstrumentedStore) Close() error
- func (s *InstrumentedStore) Delete(ctx context.Context, key string) error
- func (s *InstrumentedStore) Download(ctx context.Context, key string) (io.ReadCloser, error)
- func (s *InstrumentedStore) Exists(ctx context.Context, key string) (bool, error)
- func (s *InstrumentedStore) List(ctx context.Context, prefix string) ([]string, error)
- func (s *InstrumentedStore) Upload(ctx context.Context, key string, data io.Reader) error
- type JSONCodec
- type KeyBuilder
- type LocalStore
- func (s *LocalStore) Close() error
- func (s *LocalStore) Delete(_ context.Context, key string) error
- func (s *LocalStore) Download(_ context.Context, key string) (io.ReadCloser, error)
- func (s *LocalStore) Exists(_ context.Context, key string) (bool, error)
- func (s *LocalStore) List(_ context.Context, prefix string) ([]string, error)
- func (s *LocalStore) Upload(_ context.Context, key string, data io.Reader) error
- type RawStore
- type S3Config
- type S3Store
- func (s *S3Store) Close() error
- func (s *S3Store) Delete(ctx context.Context, key string) error
- func (s *S3Store) Download(ctx context.Context, key string) (io.ReadCloser, error)
- func (s *S3Store) Exists(ctx context.Context, key string) (bool, error)
- func (s *S3Store) List(ctx context.Context, prefix string) ([]string, error)
- func (s *S3Store) Upload(ctx context.Context, key string, data io.Reader) error
- type Store
- type TypedStore
- func (s *TypedStore[T]) Close() error
- func (s *TypedStore[T]) Delete(ctx context.Context, key string) error
- func (s *TypedStore[T]) Exists(ctx context.Context, key string) (bool, error)
- func (s *TypedStore[T]) List(ctx context.Context, prefix string) ([]string, error)
- func (s *TypedStore[T]) Load(ctx context.Context, key string) (T, error)
- func (s *TypedStore[T]) Save(ctx context.Context, key string, value T) error
Constants ¶
const ( // FileTypeDirectory represents a directory artifact type. FileTypeDirectory = "directory" // FileTypeFile represents a single-file artifact type. FileTypeFile = "file" // FileTypeArchive represents a tar.gz archive artifact type. FileTypeArchive = "archive" )
const (
// MaxUploadSize is the maximum size for uploads (1GB).
MaxUploadSize = 1 << 30
)
Variables ¶
This section is empty.
Functions ¶
func ArchiveDirectory ¶
ArchiveDirectory creates a tar.gz archive of a directory.
func DeletePrefix ¶
DeletePrefix removes every key stored under the given prefix. It lists the prefix and deletes each key, continuing past individual failures and reporting the first error encountered.
func DownloadFile ¶
DownloadFile downloads the data stored under key to a local path. Supported types: "file" writes the file (creating parent directories); "directory"/"archive" extracts a tar.gz stream into destPath.
func ExtractArchive ¶
ExtractArchive extracts a tar.gz archive to a directory.
func UploadFile ¶
UploadFile uploads a file or directory from the local filesystem to the store under the given key. Supported types: "file" uploads the file as-is; "directory"/"archive" stream a tar.gz of the directory via io.Pipe. An empty typ auto-detects from the source path. Uploads are capped at MaxUploadSize (enforced by RawStore implementations).
Types ¶
type BytesCodec ¶
type BytesCodec struct{}
BytesCodec is a pass-through codec for []byte values.
type Codec ¶
type Codec[T any] interface { // Encode serializes a value into a reader. Encode(value T) (io.Reader, error) // Decode deserializes a value from a reader. Decode(reader io.Reader) (T, error) }
Codec defines a serialization strategy for type T.
type InstrumentedStore ¶
type InstrumentedStore struct {
// contains filtered or unexported fields
}
InstrumentedStore wraps any RawStore with OpenTelemetry spans and metrics. When OTel config is not in context, all calls delegate directly to the inner store with zero overhead.
func (*InstrumentedStore) Close ¶
func (s *InstrumentedStore) Close() error
func (*InstrumentedStore) Delete ¶
func (s *InstrumentedStore) Delete(ctx context.Context, key string) error
func (*InstrumentedStore) Download ¶
func (s *InstrumentedStore) Download(ctx context.Context, key string) (io.ReadCloser, error)
type JSONCodec ¶
type JSONCodec[T any] struct{}
JSONCodec serializes and deserializes values as JSON.
type KeyBuilder ¶
type KeyBuilder struct {
// contains filtered or unexported fields
}
KeyBuilder provides composable key generation for storage keys. Keys are built by appending path segments and joining them with slashes. KeyBuilder is immutable — each With* method returns a new instance, making it safe to branch from a shared base.
func (*KeyBuilder) Build ¶
func (kb *KeyBuilder) Build() string
Build joins all segments with slashes and returns the key.
func (*KeyBuilder) WithName ¶
func (kb *KeyBuilder) WithName(name string) *KeyBuilder
WithName appends a name segment.
func (*KeyBuilder) WithRun ¶
func (kb *KeyBuilder) WithRun(id string) *KeyBuilder
WithRun appends a run ID segment.
func (*KeyBuilder) WithStep ¶
func (kb *KeyBuilder) WithStep(name string) *KeyBuilder
WithStep appends a step name segment.
func (*KeyBuilder) WithWorkflow ¶
func (kb *KeyBuilder) WithWorkflow(id string) *KeyBuilder
WithWorkflow appends a workflow ID segment.
type LocalStore ¶
type LocalStore struct {
// contains filtered or unexported fields
}
LocalStore implements RawStore using the local filesystem.
func NewLocalStore ¶
func NewLocalStore(basePath string) (*LocalStore, error)
NewLocalStore creates a new LocalStore rooted at basePath. The base directory is created if it does not exist.
func (*LocalStore) Delete ¶
func (s *LocalStore) Delete(_ context.Context, key string) error
Delete removes the data stored under the given key.
func (*LocalStore) Download ¶
func (s *LocalStore) Download(_ context.Context, key string) (io.ReadCloser, error)
Download retrieves data for the given key from the local filesystem.
type RawStore ¶
type RawStore interface {
// Upload stores data under the given key.
Upload(ctx context.Context, key string, data io.Reader) error
// Download retrieves data for the given key.
// The caller must close the returned ReadCloser.
Download(ctx context.Context, key string) (io.ReadCloser, error)
// Delete removes the data stored under the given key.
Delete(ctx context.Context, key string) error
// Exists checks whether data exists under the given key.
Exists(ctx context.Context, key string) (bool, error)
// List returns all keys matching the given prefix.
List(ctx context.Context, prefix string) ([]string, error)
// Close releases any resources held by the store.
Close() error
}
RawStore is a byte-level storage interface. Implementations handle raw byte persistence with string keys.
func NewInstrumentedStore ¶
NewInstrumentedStore creates a new InstrumentedStore wrapping the given store.
type S3Config ¶
type S3Config struct {
// Endpoint is the S3-compatible server endpoint (e.g., "localhost:9000")
Endpoint string
// AccessKey is the access key ID
AccessKey string
// SecretKey is the secret access key
SecretKey string
// Bucket is the bucket name for storing data
Bucket string
// Prefix is an optional prefix for all object keys
Prefix string
// UseSSL determines whether to use HTTPS
UseSSL bool
// Region is the bucket region (defaults to "us-east-1" if empty)
Region string
}
S3Config contains configuration for connecting to an S3-compatible storage service.
type S3Store ¶
type S3Store struct {
// contains filtered or unexported fields
}
S3Store implements RawStore using S3-compatible storage via AWS SDK v2.
func (*S3Store) Download ¶
Download retrieves data for the given key. The caller must close the returned ReadCloser.
type Store ¶
type Store[T any] interface { // Save serializes and stores the value under the given key. Save(ctx context.Context, key string, value T) error // Load retrieves and deserializes the value stored under the given key. Load(ctx context.Context, key string) (T, error) // Delete removes the data stored under the given key. Delete(ctx context.Context, key string) error // Exists checks whether data exists under the given key. Exists(ctx context.Context, key string) (bool, error) // List returns all keys matching the given prefix. List(ctx context.Context, prefix string) ([]string, error) // Close releases any resources held by the store. Close() error }
Store is a typed storage interface with automatic serialization.
func NewBytesStore ¶
NewBytesStore creates a Store[[]byte] that passes through raw bytes.
func NewJSONStore ¶
NewJSONStore creates a Store[T] that serializes values as JSON.
type TypedStore ¶
type TypedStore[T any] struct { // contains filtered or unexported fields }
TypedStore adapts a RawStore with a Codec to implement Store[T].
func (*TypedStore[T]) Close ¶
func (s *TypedStore[T]) Close() error
Close releases any resources held by the underlying RawStore.
func (*TypedStore[T]) Delete ¶
func (s *TypedStore[T]) Delete(ctx context.Context, key string) error
Delete removes the data stored under the given key.