storage

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 32 Imported by: 0

Documentation

Overview

Package storage supplies typed object storage with explicit resource bounds, provider capabilities and mutation outcomes. Applications use Disk; adapters implement Backend without buffering an entire unknown-length object.

Index

Constants

View Source
const (
	DefaultMaxStreams        = 256
	DefaultStreamIdleTimeout = 2 * time.Minute
)
View Source
const MaxBatchDelete = 1000

MaxBatchDelete bounds one DeleteMany or DeletePrefix page.

View Source
const MaxContentTypeBytes = 512
View Source
const MaxCursorBytes = 8192
View Source
const (
	MaxCustomMetadataBytes = 2 << 10
)
View Source
const MaxKeyBytes = 1024
View Source
const MaxLinkLifetime = 7 * 24 * time.Hour
View Source
const MaxPageSize = 1000

Variables

This section is empty.

Functions

func Module

func Module(name foundation.ProviderID, key foundation.Key[*Disk], declaration Declaration, config Config, requires []foundation.ProviderID, backend func(foundation.Resolver) (Backend, error)) foundation.Module

Module builds one disk per application. requires names providers owning its borrowed backend, so disk operations/readers drain before the backend closes. The backend factory must construct without I/O; adapter modules start at boot.

Types

type Backend

Backend implementations stream with bounded buffers and preserve cancellation. Put never closes its caller-owned source. A blocked uncooperative source may delay cancellation; capacity remains owned until the actual call exits. Open transfers a reader whose Close is safe concurrently with Read and interrupts it where supported. A reader returned alongside an error must still be closed.

Each successful mutation must be fully published. Errors classify whether it was unchanged, applied or uncertain; adapters never blindly retry mutations. Complete metadata and object bytes must describe the same version. Delete is idempotent only when unconditional; a missing conditional target conflicts. List is bounded and not a transactional snapshot. Never return directories, upload fragments or internal metadata as objects; entries that cannot be represented as framework objects are skipped and counted in Page.Skipped. Backend lifetime is borrowed by Disk: close the Disk and wait for Done before closing its adapter.

type BatchDeleter

type BatchDeleter interface {
	DeleteBatch(ctx context.Context, keys []ObjectKey) ([]error, error)
}

BatchDeleter deletes several keys unconditionally in one provider request. Results align with keys; nil means deleted or already absent. A call-level error means the batch outcome is unknown for every key without a result.

type ByteRange

type ByteRange struct{ Offset, Length int64 }

ByteRange requests up to Length bytes from Offset. The returned range is clipped at EOF. An empty object or starting beyond EOF is unsatisfiable.

func (ByteRange) Resolve

func (r ByteRange) Resolve(size int64) (offset, length int64, err error)

func (ByteRange) Validate

func (r ByteRange) Validate() error

type Capabilities

type Capabilities struct {
	// RequiresNFCKeys restricts object keys, namespaces and listing prefixes to
	// Unicode NFC. Adapters reject other spellings; they never normalize input
	// into another object's identity. Local storage and AWS do not require NFC.
	RequiresNFCKeys    bool
	Ranges             bool
	ConditionalRead    bool
	ConditionalCreate  bool
	ConditionalReplace bool
	ConditionalDelete  bool
	Versions           bool
	// ConditionalVersionDelete permits IfMatch together with an explicit Version
	// on Delete. Providers that evaluate a delete condition against the current
	// object (AWS) leave it false: an explicit immutable Version already selects
	// exactly one object, so callers delete by Version alone.
	ConditionalVersionDelete bool
	// DelimitedList supports one-level ListOptions.Delimited listings that
	// report child prefixes as Page.Directories.
	DelimitedList bool
	// ObjectMetadata supports the optional PutOptions.Metadata fields (cache
	// and presentation headers, custom metadata, storage class, encryption key).
	ObjectMetadata bool
	// ConditionalWriteMaxBytes, when positive, requires a declared Size within
	// this bound for conditional creates/replacements. Zero adds no size limit.
	ConditionalWriteMaxBytes int64
}

Capabilities are immutable adapter guarantees. Unsupported options must fail before consuming a source or mutating data; no option may be silently ignored. Individual flags describe single options; the combination flags below make provider limits on combined selectors explicit. ValidatePut, ValidateRead and ValidateDelete are the shared checks used by Disk and adapters alike.

func (Capabilities) ValidateDelete

func (c Capabilities) ValidateDelete(options DeleteOptions) error

ValidateDelete rejects deletion selectors, including unsupported combinations, before any provider request. A version selector deletes exactly that version.

func (Capabilities) ValidateList

func (c Capabilities) ValidateList(options ListOptions) error

ValidateList rejects listing modes the adapter cannot represent.

func (Capabilities) ValidatePut

func (c Capabilities) ValidatePut(options PutOptions) error

ValidatePut rejects an unsupported write contract before consuming its source. Adapters and Disk share this check; object-size/config validation is separate.

func (Capabilities) ValidateRead

func (c Capabilities) ValidateRead(options ReadOptions) error

ValidateRead rejects read selectors the adapter cannot honor exactly.

type CleanupID

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

CleanupID identifies provider cleanup work (for example a multipart upload). It is opaque diagnostic data; ordinary formatting deliberately hides it.

func NewCleanupID

func NewCleanupID(text string) CleanupID

func (CleanupID) Format

func (CleanupID) Format(s fmt.State, _ rune)

func (CleanupID) Value

func (id CleanupID) Value() string

type Code

type Code string

Code is comparable with errors.Is; provider causes are retained but redacted.

const (
	NotFound            Code = "storage_not_found"
	Forbidden           Code = "storage_forbidden"
	Unsupported         Code = "storage_unsupported"
	PreconditionFailed  Code = "storage_precondition_failed"
	RangeNotSatisfiable Code = "storage_range_not_satisfiable"
	LimitExceeded       Code = "storage_limit_exceeded"
	Invalid             Code = "storage_invalid"
	Unavailable         Code = "storage_unavailable"
	IntegrityFailed     Code = "storage_integrity_failed"
	Closed              Code = "storage_closed"
)

func (Code) Error

func (c Code) Error() string

type Config

type Config struct {
	Visibility        Visibility
	MaxObjectBytes    int64
	MaxActive         int
	Timeout           time.Duration
	MaxStreams        int
	StreamIdleTimeout time.Duration
}

Config bounds one disk. MaxActive and Timeout apply to metadata and write operations (Put, Stat, Delete, List, signing) and to opening a read stream. An open read stream uses a separate MaxStreams pool and remains open while it makes progress: StreamIdleTimeout cancels it only after no read progress for that long, so a slow client download is neither cut off by Timeout nor able to exhaust write capacity. Capacity waits are queued (at most min(Timeout, 5s)) and then fail as retryable overload (fault.Overloaded). Zero MaxStreams or StreamIdleTimeout selects its default.

func DefaultConfig

func DefaultConfig() Config

func (Config) Validate

func (c Config) Validate() error

type CopyOptions

type CopyOptions struct {
	Source      ReadOptions
	Destination PutOptions
}

CopyOptions reads one complete source version and publishes a destination. Destination metadata defaults to the source's media type, exact size and available checksum. Conditions remain explicit. Copies between disks sharing one ServerCopier adapter run inside the provider; other copies stream with the adapters' bounded buffers. Neither buffers the entire object.

type Cursor

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

Cursor is an opaque provider continuation. Copy it only from the returned page; it is tied to that disk/prefix, and never grants object authorization.

func NewCursor

func NewCursor(text string) Cursor

func (Cursor) IsZero

func (c Cursor) IsZero() bool

func (Cursor) Token

func (c Cursor) Token() string

type Declaration

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

Declaration is a reusable typed disk descriptor. IDs are explicit, not guessed from default configuration. Separate domain concerns should declare disks once.

func DefineDisk

func DefineDisk(id DiskID) Declaration

func (Declaration) Bind

func (d Declaration) Bind(backend Backend, config Config) (*Disk, error)

func (Declaration) ID

func (d Declaration) ID() DiskID

func (Declaration) Resolve

func (d Declaration) Resolve(registry *Registry) (*Disk, error)

func (Declaration) Validate

func (d Declaration) Validate() error

type DeleteFailure

type DeleteFailure struct {
	Key ObjectKey
	Err error
}

DeleteFailure is one key a batch did not delete; Err is a classified *Error whose Outcome distinguishes unchanged from uncertain deletion.

type DeleteManyResult

type DeleteManyResult struct {
	Deleted []ObjectKey
	Failed  []DeleteFailure
}

type DeleteOptions

type DeleteOptions struct {
	IfMatch ETag
	Version VersionID
}

func (DeleteOptions) Validate

func (o DeleteOptions) Validate() error

type DeletePrefixOptions

type DeletePrefixOptions struct {
	Prefix Prefix
	Cursor Cursor
	Limit  int
}

DeletePrefixOptions selects one bounded page below a nonempty prefix.

type DeletePrefixResult

type DeletePrefixResult struct {
	DeleteManyResult
	Skipped int
	Next    Cursor
}

DeletePrefixResult reports one page. Skipped entries (foreign or oversized objects) are never deleted. Continue with Next until it is zero.

type Disk

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

Disk owns bounded operations and returned readers, borrowing its backend. Metadata/write operations and open read streams use separate queued admission pools. Close cancels work and closes readers; Done waits for their actual release. Close the backend only afterward. Construction performs no storage I/O.

func NewDisk

func NewDisk(id DiskID, backend Backend, config Config) (*Disk, error)

func (*Disk) Capabilities

func (d *Disk) Capabilities() Capabilities

func (*Disk) Close

func (d *Disk) Close(ctx context.Context) error

func (*Disk) Config

func (d *Disk) Config() Config

Config returns the disk's normalized limits. Recovery policies use Timeout to bound how long an admitted operation can still be running.

func (*Disk) CopyTo

func (d *Disk) CopyTo(ctx context.Context, source ObjectKey, destination *Disk, target ObjectKey, options CopyOptions) (StoredObject, error)

CopyTo copies this disk's source to destination without deleting the source. A same-adapter copy uses ServerCopier when available and holds one operation slot on each disk. A streamed copy holds a read stream on the source disk and an operation slot on the destination. Source close failures after a successful publication report Applied. The returned object is zero on any failure; reconcile uncertain writes by key.

func (*Disk) Delete

func (d *Disk) Delete(ctx context.Context, key ObjectKey, options DeleteOptions) error

func (*Disk) DeleteMany

func (d *Disk) DeleteMany(ctx context.Context, keys []ObjectKey) (DeleteManyResult, error)

DeleteMany unconditionally deletes up to MaxBatchDelete distinct keys under one operation slot, using BatchDeleter when the adapter provides it. It is idempotent for absent keys and never implies a transaction: inspect Failed. A call-level error reports keys whose outcome is unknown as Failed.

func (*Disk) DeletePrefix

func (d *Disk) DeletePrefix(ctx context.Context, options DeletePrefixOptions) (DeletePrefixResult, error)

DeletePrefix lists one page under a nonempty prefix and deletes its objects unconditionally. It is not a snapshot: objects written concurrently can survive, and a directory is never implied to be empty afterwards.

func (*Disk) Done

func (d *Disk) Done() <-chan struct{}

func (*Disk) Exists

func (d *Disk) Exists(ctx context.Context, key ObjectKey) (bool, error)

func (*Disk) ID

func (d *Disk) ID() DiskID

func (*Disk) List

func (d *Disk) List(ctx context.Context, options ListOptions) (Page, error)

func (*Disk) MoveTo

func (d *Disk) MoveTo(ctx context.Context, source ObjectKey, destination *Disk, target ObjectKey, options CopyOptions) (MoveResult, error)

MoveTo is copy-then-conditional-delete, not an atomic rename. It pins the source with its ETag and preserves replacements with a different validator. Adapters without conditional read/delete are rejected before writing the destination. Both adapters must expose ObjectLocator. Physical aliases are rejected even if their disk names, namespaces or logical keys differ. Distinct stores can use the same logical key.

func (*Disk) Open

func (d *Disk) Open(ctx context.Context, key ObjectKey, options ReadOptions) (io.ReadCloser, ReadInfo, error)

Open returns an owned reader holding one MaxStreams slot until Close, cancellation, shutdown or StreamIdleTimeout without read progress. Opening itself must complete within Timeout. A stream is not bounded by Timeout, so a slow consumer can finish a large download while it keeps reading.

func (*Disk) OpenSeek

func (d *Disk) OpenSeek(ctx context.Context, key ObjectKey, options ReadOptions) (io.ReadSeekCloser, ObjectInfo, error)

OpenSeek supplies a bounded-memory seekable view of one complete object. Seeking reopens a range pinned to its immutable version or strong ETag; a replacement fails its precondition rather than mixing two representations. A backend must support ranges and either version reads or conditional reads. Stat runs immediately; payloads open only on Read. Close the returned handle. Seeking concurrently with Read is serialized; Close cancels and drains Read.

func (*Disk) PublicURL

func (d *Disk) PublicURL(ctx context.Context, key ObjectKey) (string, error)

func (*Disk) Put

func (d *Disk) Put(ctx context.Context, key ObjectKey, source io.Reader, options PutOptions) (StoredObject, error)

func (*Disk) PutBytes

func (d *Disk) PutBytes(ctx context.Context, key ObjectKey, data []byte, options PutOptions) (StoredObject, error)

func (*Disk) PutFile

func (d *Disk) PutFile(ctx context.Context, key ObjectKey, path string, options PutOptions) (StoredObject, error)

PutFile opens a trusted application-selected regular file and delegates to Put. It never interprets an object key or client upload filename as a filesystem path. The caller's file is not removed or modified. Concurrent file changes can fail the exact length or optional checksum check; take a snapshot when required.

func (*Disk) ReadBytes

func (d *Disk) ReadBytes(ctx context.Context, key ObjectKey, maximum int64, options ReadOptions) ([]byte, ReadInfo, error)

ReadBytes is an explicitly bounded in-memory convenience. For large objects, use Open. It closes its reader on success and failure and returns no partial bytes. maximum applies to the requested span, not the complete object.

func (*Disk) Stat

func (d *Disk) Stat(ctx context.Context, key ObjectKey, options ReadOptions) (ObjectInfo, error)

func (*Disk) Stats

func (d *Disk) Stats() Stats

func (*Disk) TemporaryURL

func (d *Disk) TemporaryURL(ctx context.Context, key ObjectKey, options LinkOptions) (TemporaryURL, error)

func (*Disk) TemporaryUploadForm

func (d *Disk) TemporaryUploadForm(ctx context.Context, key ObjectKey, options UploadFormOptions) (UploadForm, error)

TemporaryUploadForm signs a direct browser form upload for an application-selected key. Authorize the caller first: the form is a bearer write credential until it expires. Prefer TemporaryUploadURL when the client can send a PUT request; use a form when an HTML form posts the file.

func (*Disk) TemporaryUploadURL

func (d *Disk) TemporaryUploadURL(ctx context.Context, key ObjectKey, options UploadLinkOptions) (UploadLink, error)

TemporaryUploadURL signs a direct client upload for an application-selected key. Authorize the caller first: the link is a bearer write credential until it expires. It is available on private disks; Visibility governs reads only.

func (*Disk) Validate

func (d *Disk) Validate() error

type DiskID

type DiskID string

DiskID is an explicit registered disk, not an object key or filesystem path.

func (DiskID) Validate

func (d DiskID) Validate() error

type ETag

type ETag string

ETag is an opaque strong object validator, including its quotes. It is not assumed to be an MD5 or other content digest. Zero means no validator.

func (ETag) Validate

func (t ETag) Validate() error

type Error

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

func Failure

func Failure(code Code, op Operation, outcome Outcome, cause error) *Error

func (*Error) Cleanup

func (e *Error) Cleanup() value.Optional[CleanupID]

func (*Error) Code

func (e *Error) Code() Code

func (*Error) Error

func (e *Error) Error() string

func (*Error) Format

func (e *Error) Format(s fmt.State, _ rune)

func (*Error) Is

func (e *Error) Is(target error) bool

func (*Error) LogValue

func (e *Error) LogValue() slog.Value

func (*Error) Operation

func (e *Error) Operation() Operation

func (*Error) Outcome

func (e *Error) Outcome() Outcome

func (*Error) Unwrap

func (e *Error) Unwrap() error

func (*Error) WithCleanup

func (e *Error) WithCleanup(id CleanupID) *Error

type FormField

type FormField struct{ Name, Value string }

FormField is one signed form value. Submit every field unchanged, then the file content last in the field named by UploadForm.FileField.

type LinkOptions

type LinkOptions struct {
	ExpiresIn                  time.Duration
	Version                    VersionID
	ResponseContentType        MediaType
	ResponseContentDisposition string
}

LinkOptions bounds one signed read. ResponseContentType and ResponseContentDisposition are signed provider response overrides (for example to force a download filename); use RFC 8187 encoding for non-ASCII filenames. They never change stored object metadata.

func (LinkOptions) Validate

func (o LinkOptions) Validate() error

type ListOptions

type ListOptions struct {
	Prefix    Prefix
	Cursor    Cursor
	Limit     int
	Delimited bool
}

ListOptions selects one bounded page. Delimited lists a single level below Prefix: objects without a further "/" after Prefix and each distinct child prefix ending in "/" (reported once in Page.Directories). It requires Capabilities.DelimitedList. Limit bounds objects and directories together.

func (ListOptions) Validate

func (o ListOptions) Validate() error

type MediaType

type MediaType string

MediaType is stored object metadata, not proof of a validated file format.

const Binary MediaType = "application/octet-stream"

func (MediaType) Validate

func (m MediaType) Validate() error

type MoveResult

type MoveResult struct {
	Destination        value.Optional[StoredObject]
	DestinationOutcome Outcome
	SourceOutcome      Outcome
}

MoveResult records the two separately committed effects. A failed move can retain a complete Destination. SourceOutcome distinguishes a preserved source from an applied or uncertain deletion. Never automatically compensate by deleting Destination: another writer might already have replaced it.

type ObjectAddress

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

ObjectAddress identifies a provider object independently of disk names and namespace aliases. Adapters use a stable store identity and the complete key. It is opaque operational metadata, not a URL, authorization token or DB ID.

func NewObjectAddress

func NewObjectAddress(store, object string) (ObjectAddress, error)

func (ObjectAddress) Format

func (ObjectAddress) Format(s fmt.State, _ rune)

type ObjectInfo

type ObjectInfo struct {
	Key         ObjectKey
	Size        int64
	ContentType MediaType
	Modified    temporal.DateTime
	ETag        ETag
	Version     VersionID
	Checksum    value.Optional[SHA256]
}

ObjectInfo describes a complete object. Checksum is a full-object SHA-256 when available; do not compare it to the bytes of a partial ranged read.

func (ObjectInfo) Validate

func (i ObjectInfo) Validate() error

func (ObjectInfo) ValidateListed

func (i ObjectInfo) ValidateListed() error

ValidateListed checks a listing entry. A listing may not report the media type; a zero ContentType is accepted there and nowhere else.

type ObjectKey

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

ObjectKey is a validated, case-sensitive UTF-8 object name. It is never a filesystem path or URL. Parsing rejects traversal and ambiguous separators; it never cleans, case-folds, percent-decodes or Unicode-normalizes a key.

func ParseKey

func ParseKey(text string) (ObjectKey, error)

func (ObjectKey) IsZero

func (k ObjectKey) IsZero() bool

func (ObjectKey) JSONContract

func (ObjectKey) JSONContract() contract.JSON[ObjectKey]

func (ObjectKey) MarshalJSON

func (k ObjectKey) MarshalJSON() ([]byte, error)

func (ObjectKey) MarshalText

func (k ObjectKey) MarshalText() ([]byte, error)

func (ObjectKey) String

func (k ObjectKey) String() string

func (*ObjectKey) UnmarshalJSON

func (k *ObjectKey) UnmarshalJSON(data []byte) error

func (*ObjectKey) UnmarshalText

func (k *ObjectKey) UnmarshalText(text []byte) error

func (ObjectKey) Validate

func (k ObjectKey) Validate() error

type ObjectLocator

type ObjectLocator interface {
	Locate(ObjectKey) (ObjectAddress, error)
}

ObjectLocator lets safe moves reject aliases of the same physical object. Locate performs no I/O. Return the same store identity across adapter instances for the same store, and account for Namespace in the complete object key.

type ObjectMetadata

type ObjectMetadata struct {
	CacheControl       string
	ContentDisposition string
	ContentEncoding    string
	StorageClass       StorageClass
	EncryptionKey      string
	Custom             map[string]string
}

ObjectMetadata is optional per-object provider metadata. Header values are printable ASCII; use RFC 8187 encoding for non-ASCII Content-Disposition filenames. Custom names are lowercase letters, digits and '-' and must not use the reserved "foundry-" prefix. EncryptionKey selects a provider-managed SSE-KMS key identifier; it is an identifier, never key material. Metadata is written with the object; listings and Stat do not echo it back.

func (ObjectMetadata) Clone

func (m ObjectMetadata) Clone() ObjectMetadata

Clone returns metadata that shares no mutable state with the caller.

func (ObjectMetadata) IsZero

func (m ObjectMetadata) IsZero() bool

func (ObjectMetadata) Validate

func (m ObjectMetadata) Validate() error

type Operation

type Operation string
const (
	PutOperation    Operation = "put"
	OpenOperation   Operation = "open"
	StatOperation   Operation = "stat"
	DeleteOperation Operation = "delete"
	ListOperation   Operation = "list"
	CopyOperation   Operation = "copy"
	MoveOperation   Operation = "move"
	SignOperation   Operation = "sign"
	CloseOperation  Operation = "close"
)

type Outcome

type Outcome uint8

Outcome describes visibility of a mutation, not an instruction to retry. Applied errors can follow successful publication but failed cleanup/durability. Unknown means the caller must reconcile; no automatic mutation retry is safe.

const (
	NotApplicable Outcome = iota
	Unchanged
	Applied
	Unknown
)

type Page

type Page struct {
	Objects     []ObjectInfo
	Directories []Prefix
	Skipped     int
	Next        Cursor
}

Page is one listing page. Listed objects carry key, size, modification time, ETag and version from the provider listing; ContentType and Checksum are zero when the listing does not report them (S3). Use Stat for complete metadata. Skipped counts provider entries under the prefix that are not representable framework objects (foreign or unparsable keys, entries beyond the object size limit, entries without validators); they never fail a page.

type Prefix

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

Prefix selects an exact lexical prefix, not a directory or a normalized path. Zero means every object. A trailing slash is allowed for directory-like use.

func ParsePrefix

func ParsePrefix(text string) (Prefix, error)

func (Prefix) Contains

func (p Prefix) Contains(key ObjectKey) bool

func (Prefix) String

func (p Prefix) String() string

func (Prefix) Validate

func (p Prefix) Validate() error

type PublicBase

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

PublicBase is an explicitly configured public bucket/CDN root. It is not inferred from an authenticated API endpoint and does not make a bucket public. Object keys are encoded once as literal path text, including percent signs. A literal '+' is encoded as %2B because some CDNs and S3-compatible servers decode a path '+' as a space.

func ParsePublicBase

func ParsePublicBase(address string) (PublicBase, error)

func (PublicBase) IsZero

func (b PublicBase) IsZero() bool

func (PublicBase) URL

func (b PublicBase) URL(key ObjectKey) (string, error)

type PutOptions

type PutOptions struct {
	ContentType MediaType
	Size        value.Optional[int64]
	Checksum    value.Optional[SHA256]
	Condition   WriteCondition
	// Metadata is optional provider object metadata. Adapters without
	// Capabilities.ObjectMetadata reject a nonzero value before consuming input.
	Metadata ObjectMetadata
}

func (PutOptions) Validate

func (o PutOptions) Validate(maximum int64) error

type ReadInfo

type ReadInfo struct {
	Object         ObjectInfo
	Offset, Length int64
}

ReadInfo separates the complete object's metadata from the returned byte span.

type ReadOptions

type ReadOptions struct {
	Range   value.Optional[ByteRange]
	IfMatch ETag
	Version VersionID
}

func (ReadOptions) Validate

func (o ReadOptions) Validate() error

type Registry

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

Registry is immutable and borrows its disks. The lifecycle owner closes each disk before its backend. Registry construction and resolution perform no I/O.

func NewDefaultRegistry

func NewDefaultRegistry(selected DiskID, disks ...*Disk) (*Registry, error)

NewDefaultRegistry selects an existing disk. Default is an alias, never a separately opened backend. NewRegistry remains available for explicit-only use.

func NewRegistry

func NewRegistry(disks ...*Disk) (*Registry, error)

func (*Registry) Default

func (r *Registry) Default() (*Disk, error)

func (*Registry) DefaultName

func (r *Registry) DefaultName() DiskID

func (*Registry) Disk

func (r *Registry) Disk(id DiskID) (*Disk, error)

func (*Registry) Disks

func (r *Registry) Disks() []DiskID

type SHA256

type SHA256 [32]byte

func ParseSHA256

func ParseSHA256(text string) (SHA256, error)

func (SHA256) String

func (s SHA256) String() string

type ServerCopier

type ServerCopier interface {
	Copy(ctx context.Context, source, target ObjectKey, options CopyOptions, maximum int64) (ObjectInfo, error)
}

ServerCopier copies within one adapter without streaming bytes through this process (for example S3 CopyObject or a local kernel-assisted file copy). It honors the same source pins, destination condition and declared size/checksum as a streamed copy, and writes the metadata a streamed copy writes: the destination's content type (the source's by default), the source's recorded full checksum and options.Destination.Metadata, never other source metadata such as cache or custom headers. A source larger than maximum (the smaller of both disks' MaxObjectBytes) fails with LimitExceeded and an Unchanged outcome before any mutation. When a request needs the streamed path, it returns Unsupported with an Unchanged outcome before any provider mutation.

type SignedFormProvider

type SignedFormProvider interface {
	TemporaryUploadForm(context.Context, ObjectKey, UploadFormOptions) (UploadForm, error)
}

SignedFormProvider presigns a browser form upload (an HTML POST policy).

type SignedURLProvider

type SignedURLProvider interface {
	TemporaryURL(context.Context, ObjectKey, LinkOptions) (TemporaryURL, error)
}

SignedURLProvider produces a read-only bearer URL. A URL remains usable until expiry/credential revocation even if the framework disk subsequently closes.

type SignedUploadProvider

type SignedUploadProvider interface {
	TemporaryUploadURL(context.Context, ObjectKey, UploadLinkOptions) (UploadLink, error)
}

SignedUploadProvider produces a presigned single-request upload. The exact size, media type, optional checksum metadata and optional absence condition are signed; the client must send UploadLink.Headers unchanged.

type Stats

type Stats struct {
	Active  int
	Streams int
	Closing bool
}

Stats reports admitted work. Active counts operations and open streams; Streams is the subset holding MaxStreams slots.

type StorageClass

type StorageClass string

StorageClass is a provider storage tier such as STANDARD or STANDARD_IA. It is passed to the provider verbatim; zero selects the bucket default.

type StoredObject

type StoredObject struct {
	Disk   DiskID
	Object ObjectInfo
}

type TemporaryURL

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

TemporaryURL deliberately redacts formatting and rejects implicit JSON. Explicitly call URL when returning a link in an authorized response DTO. ExpiresAt is an upper bound: revoked/expired credentials may invalidate it sooner.

func NewTemporaryURL

func NewTemporaryURL(address string, expires time.Time) (TemporaryURL, error)

func (TemporaryURL) ExpiresAt

func (u TemporaryURL) ExpiresAt() time.Time

func (TemporaryURL) Format

func (TemporaryURL) Format(s fmt.State, _ rune)

func (TemporaryURL) LogValue

func (TemporaryURL) LogValue() slog.Value

func (TemporaryURL) MarshalJSON

func (TemporaryURL) MarshalJSON() ([]byte, error)

func (TemporaryURL) String

func (TemporaryURL) String() string

func (TemporaryURL) URL

func (u TemporaryURL) URL() string

type URLProvider

type URLProvider interface {
	PublicURL(context.Context, ObjectKey) (string, error)
}

type UploadForm

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

UploadForm is a signed bearer form upload. Formatting redacts it and implicit JSON fails; explicitly return URL, Fields and FileField in an authorized response DTO. The object is written by the browser, not by this process: confirm it with Stat (and its checksum) before relying on it.

func NewUploadForm

func NewUploadForm(address string, fields []FormField, expires time.Time) (UploadForm, error)

func (UploadForm) ExpiresAt

func (f UploadForm) ExpiresAt() time.Time

func (UploadForm) Fields

func (f UploadForm) Fields() []FormField

func (UploadForm) FileField

func (UploadForm) FileField() string

func (UploadForm) Format

func (UploadForm) Format(s fmt.State, _ rune)

func (UploadForm) LogValue

func (UploadForm) LogValue() slog.Value

func (UploadForm) MarshalJSON

func (UploadForm) MarshalJSON() ([]byte, error)

func (UploadForm) String

func (UploadForm) String() string

func (UploadForm) URL

func (f UploadForm) URL() string

type UploadFormOptions

type UploadFormOptions struct {
	ExpiresIn        time.Duration
	ContentType      MediaType
	MinSize, MaxSize int64
	Checksum         value.Optional[SHA256]
}

UploadFormOptions constrains a direct browser form upload. The object key and ContentType are exact and the uploaded size must lie within [MinSize, MaxSize] (a signed content-length-range). Checksum, when set, is recorded as the object's full SHA-256 metadata; the provider does not verify it, but complete framework reads do. Form uploads take no write condition.

func (UploadFormOptions) Validate

func (o UploadFormOptions) Validate(maximum int64) error
type UploadLink struct {
	// contains filtered or unexported fields
}

UploadLink is a signed bearer upload request. Formatting redacts it and implicit JSON fails; explicitly return URL, Method and Headers in an authorized response DTO. The object is written by the client, not by this process: confirm it with Stat (and its checksum) before relying on it.

func NewUploadLink(address, method string, headers http.Header, expires time.Time) (UploadLink, error)

func (UploadLink) ExpiresAt

func (l UploadLink) ExpiresAt() time.Time

func (UploadLink) Format

func (UploadLink) Format(s fmt.State, _ rune)

func (UploadLink) Headers

func (l UploadLink) Headers() http.Header

func (UploadLink) LogValue

func (UploadLink) LogValue() slog.Value

func (UploadLink) MarshalJSON

func (UploadLink) MarshalJSON() ([]byte, error)

func (UploadLink) Method

func (l UploadLink) Method() string

func (UploadLink) String

func (UploadLink) String() string

func (UploadLink) URL

func (l UploadLink) URL() string

type UploadLinkOptions

type UploadLinkOptions struct {
	ExpiresIn   time.Duration
	ContentType MediaType
	Size        int64
	Checksum    value.Optional[SHA256]
	Condition   WriteCondition
}

UploadLinkOptions describes a direct client upload. ContentType and Size are required and exact; Size must be at least one byte (a zero length is not signed, so an empty link would accept any size). Checksum is recorded as the object's full SHA-256 metadata; the provider does not verify it, but complete framework reads do. Condition supports IfAbsent only where the disk supports conditional create.

func (UploadLinkOptions) Validate

func (o UploadLinkOptions) Validate(maximum int64) error

type VersionID

type VersionID string

VersionID selects an immutable provider object version. A local generation validator is an ETag, not a promise that previous versions remain readable.

func (VersionID) Validate

func (v VersionID) Validate() error

type Visibility

type Visibility uint8

Visibility is access intent. Foundry never changes object ACLs/bucket policy. Private disks reject stable public URLs even if their adapter has a CDN base.

const (
	Private Visibility = iota
	Public
)

type WriteCondition

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

func IfAbsent

func IfAbsent() WriteCondition

func IfMatch

func IfMatch(tag ETag) (WriteCondition, error)

func (WriteCondition) Match

func (c WriteCondition) Match() ETag

func (WriteCondition) RequiresAbsence

func (c WriteCondition) RequiresAbsence() bool

Directories

Path Synopsis
Package http connects typed HTTP file inputs and responses to storage disks.
Package http connects typed HTTP file inputs and responses to storage disks.
Package local implements a managed, crash-aware object store under an os.Root.
Package local implements a managed, crash-aware object store under an os.Root.
Package s3 implements AWS S3, an explicit Cloudflare R2 profile and a generic S3-compatible profile using the official AWS SDK.
Package s3 implements AWS S3, an explicit Cloudflare R2 profile and a generic S3-compatible profile using the official AWS SDK.

Jump to

Keyboard shortcuts

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