Help us shape the future of Go! Take the 2026 Go Developer Survey

storage

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 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

type Backend interface {
	// Capabilities returns the immutable guarantees supported by this adapter.
	Capabilities() Capabilities
	// Put streams the borrowed source into a complete publication and reports its mutation
	// outcome on failure.
	Put(context.Context, ObjectKey, io.Reader, PutOptions) (ObjectInfo, error)
	// Open returns metadata and an owned reader for the selected object span; callers must
	// close any returned reader.
	Open(context.Context, ObjectKey, ReadOptions) (io.ReadCloser, ReadInfo, error)
	// Stat returns complete metadata for the selected object version.
	Stat(context.Context, ObjectKey, ReadOptions) (ObjectInfo, error)
	// Delete removes the selected object; an unconditional deletion of an absent object
	// succeeds.
	Delete(context.Context, ObjectKey, DeleteOptions) error
	// List returns a bounded page of objects and supported child prefixes, excluding
	// staging data.
	List(context.Context, ListOptions) (Page, error)
}

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 unconditionally deletes keys and returns aligned per-key results or a
	// call-level failure.
	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)

Resolve clips the range to size or reports an invalid or unsatisfiable range.

func (ByteRange) Validate

func (r ByteRange) Validate() error

Validate rejects negative offsets, nonpositive lengths and overflowing ranges.

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

NewCleanupID wraps an opaque cleanup reference without validating it.

func (CleanupID) Format

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

Format writes a label without exposing the cleanup reference.

func (CleanupID) Value

func (id CleanupID) Value() string

Value explicitly returns the opaque cleanup reference.

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

Error returns the classification 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

DefaultConfig returns private visibility and default object, admission and timeout limits.

func (Config) Validate

func (c Config) Validate() error

Validate rejects invalid disk bounds while allowing zero stream settings to select defaults.

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

NewCursor wraps an opaque adapter continuation token without validating it.

func (Cursor) IsZero

func (c Cursor) IsZero() bool

IsZero reports whether continuation is absent.

func (Cursor) Token

func (c Cursor) Token() string

Token returns the opaque adapter continuation.

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

DefineDisk creates an unvalidated reusable declaration for id.

func (Declaration) Bind

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

Bind constructs a disk for the declared identifier while borrowing backend.

func (Declaration) ID

func (d Declaration) ID() DiskID

ID returns the declared disk identifier.

func (Declaration) Resolve

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

Resolve validates the declaration and retrieves its disk from registry.

func (Declaration) Validate

func (d Declaration) Validate() error

Validate checks the declared disk identifier.

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
}

DeleteManyResult separates successfully deleted keys from classified per-key failures.

type DeleteOptions

type DeleteOptions struct {
	IfMatch ETag
	Version VersionID
}

DeleteOptions selects an optional validator or immutable version for deletion.

func (DeleteOptions) Validate

func (o DeleteOptions) Validate() error

Validate checks the optional validator and version syntax without checking provider support.

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)

NewDisk validates configuration and snapshots capabilities while borrowing backend; it performs no storage I/O.

func (*Disk) Capabilities

func (d *Disk) Capabilities() Capabilities

Capabilities returns the adapter guarantees captured at construction, or zero capabilities for a nil disk.

func (*Disk) Close

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

Close cancels work, closes readers and waits for actual release or ctx cancellation; it does not close the backend.

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

Delete removes the selected object using validated provider conditions; failures retain the mutation outcome.

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

Done closes after shutdown and release of all admitted work; a nil disk returns nil.

func (*Disk) Exists

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

Exists reports false without an error only when Stat classifies the object as not found.

func (*Disk) ID

func (d *Disk) ID() DiskID

ID returns the disk identifier, or an empty identifier for a nil disk.

func (*Disk) List

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

List returns a validated bounded page, counting objects above the disk size bound as skipped.

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)

PublicURL returns a validated adapter URL only when the disk has public visibility.

func (*Disk) Put

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

Put streams source within disk limits without closing it; errors retain whether publication was applied or uncertain.

func (*Disk) PutBytes

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

PutBytes stores data with its exact length; data must remain unchanged during the call.

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)

Stat returns validated complete metadata and rejects byte-range options.

func (*Disk) Stats

func (d *Disk) Stats() Stats

Stats returns a synchronized snapshot of admitted work and shutdown state.

func (*Disk) TemporaryURL

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

TemporaryURL returns a validated signed read link when the adapter supports the requested selectors.

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

Validate rejects a nil or uninitialized disk; it does not check whether shutdown has begun.

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

Validate rejects an invalid semantic disk identifier with an invalid fault.

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

Validate accepts an empty or quoted strong validator and rejects malformed tags.

type Error

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

Error retains a storage classification, operation, mutation outcome and redacted cause.

func Failure

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

Failure creates a classified error retaining cause without formatting it.

func (*Error) Cleanup

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

Cleanup returns the optional provider cleanup reference.

func (*Error) Code

func (e *Error) Code() Code

Code returns the storage failure classification.

func (*Error) Error

func (e *Error) Error() string

Error returns the classification and operation without formatting the cause.

func (*Error) Format

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

Format writes the classification and operation without exposing the cause.

func (*Error) Is

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

Is reports whether target is the same storage Code.

func (*Error) LogValue

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

LogValue returns the classification and operation without exposing the cause.

func (*Error) Operation

func (e *Error) Operation() Operation

Operation returns the operation that failed.

func (*Error) Outcome

func (e *Error) Outcome() Outcome

Outcome returns the reported mutation visibility.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the retained cause.

func (*Error) WithCleanup

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

WithCleanup returns a copy carrying id, leaving the receiver unchanged.

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

Validate checks link lifetime, response overrides and version syntax.

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

Validate checks the prefix, page limit and cursor length.

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

Validate rejects empty, excessive, wildcard or malformed media types and control characters.

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)

NewObjectAddress creates an opaque identity from nonempty, bounded store and object identifiers.

func (ObjectAddress) Format

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

Format writes a label without exposing object identity.

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

Validate checks object metadata, requiring a nonnegative size and nonzero modification time.

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)

ParseKey validates and copies text without changing its object identity.

func (ObjectKey) IsZero

func (k ObjectKey) IsZero() bool

IsZero reports whether no object key is set.

func (ObjectKey) JSONContract

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

JSONContract describes the object key as a JSON string.

func (ObjectKey) MarshalJSON

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

MarshalJSON validates the key and encodes it as a JSON string.

func (ObjectKey) MarshalText

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

MarshalText validates the key and returns its literal UTF-8 bytes.

func (ObjectKey) String

func (k ObjectKey) String() string

String returns the literal object key.

func (*ObjectKey) UnmarshalJSON

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

UnmarshalJSON clears the key and decodes a bounded, validated JSON string.

func (*ObjectKey) UnmarshalText

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

UnmarshalText clears the key and replaces it only when text is valid.

func (ObjectKey) Validate

func (k ObjectKey) Validate() error

Validate checks the literal key syntax; the zero key is invalid.

type ObjectLocator

type ObjectLocator interface {
	// Locate returns the physical object identity without performing I/O.
	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

IsZero reports whether all optional metadata fields are empty.

func (ObjectMetadata) Validate

func (m ObjectMetadata) Validate() error

Validate rejects invalid provider headers, storage classes and custom metadata names or sizes.

type Operation

type Operation string

Operation identifies the storage action associated with a failure.

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)

ParsePrefix validates and copies a lexical prefix; empty text selects all objects.

func (Prefix) Contains

func (p Prefix) Contains(key ObjectKey) bool

Contains reports whether a valid key begins with the literal prefix.

func (Prefix) String

func (p Prefix) String() string

String returns the literal prefix.

func (Prefix) Validate

func (p Prefix) Validate() error

Validate checks prefix syntax, allowing the zero prefix and a trailing slash.

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)

ParsePublicBase validates an HTTP base URL without query, credentials, fragment or dot path segments.

func (PublicBase) IsZero

func (b PublicBase) IsZero() bool

IsZero reports whether no public base is configured.

func (PublicBase) URL

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

URL appends a validated key, encoding its literal identity once.

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
}

PutOptions declares publication metadata, optional exact size and checksum, and write conditions.

func (PutOptions) Validate

func (o PutOptions) Validate(maximum int64) error

Validate checks supplied metadata, conditions and declared size against maximum.

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
}

ReadOptions selects an optional byte range, validator and immutable object version.

func (ReadOptions) Validate

func (o ReadOptions) Validate() error

Validate checks range, validator and version syntax without checking provider support.

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)

NewRegistry borrows valid disks, rejecting duplicate identifiers and excessive entries.

func (*Registry) Default

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

Default returns the selected existing disk or a missing fault when no default is configured.

func (*Registry) DefaultName

func (r *Registry) DefaultName() DiskID

DefaultName returns the selected identifier, or an empty identifier when absent.

func (*Registry) Disk

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

Disk resolves an explicit identifier, returning a missing fault for an unregistered disk.

func (*Registry) Disks

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

Disks returns an owned, sorted list of registered identifiers.

type SHA256

type SHA256 [32]byte

SHA256 is a full-object SHA-256 digest.

func ParseSHA256

func ParseSHA256(text string) (SHA256, error)

ParseSHA256 decodes exactly 32 digest bytes from hexadecimal text.

func (SHA256) String

func (s SHA256) String() string

String returns the lowercase hexadecimal digest.

type ServerCopier

type ServerCopier interface {
	// Copy publishes a complete destination within the adapter using the supplied
	// selectors and size bound.
	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 returns a signed bearer form constrained by options.
	TemporaryUploadForm(context.Context, ObjectKey, UploadFormOptions) (UploadForm, error)
}

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

type SignedURLProvider

type SignedURLProvider interface {
	// TemporaryURL returns a signed read URL constrained by options.
	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 returns a signed bearer PUT request constrained by options.
	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
}

StoredObject pairs an object description with its registered disk identifier.

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)

NewTemporaryURL validates an HTTP URL and expiry, storing the expiry in UTC.

func (TemporaryURL) ExpiresAt

func (u TemporaryURL) ExpiresAt() time.Time

ExpiresAt returns the stored upper bound on expiry.

func (TemporaryURL) Format

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

Format writes a label without exposing bearer credentials.

func (TemporaryURL) LogValue

func (TemporaryURL) LogValue() slog.Value

LogValue returns a label without exposing bearer credentials.

func (TemporaryURL) MarshalJSON

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

MarshalJSON rejects implicit export of bearer credentials.

func (TemporaryURL) String

func (TemporaryURL) String() string

String returns a label without exposing bearer credentials.

func (TemporaryURL) URL

func (u TemporaryURL) URL() string

URL explicitly returns the bearer read URL address.

type URLProvider

type URLProvider interface {
	// PublicURL returns the configured stable public address for key.
	PublicURL(context.Context, ObjectKey) (string, error)
}

URLProvider supplies stable public addresses without changing provider access policies.

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)

NewUploadForm validates and copies signed fields and normalizes expiry to UTC.

func (UploadForm) ExpiresAt

func (f UploadForm) ExpiresAt() time.Time

ExpiresAt returns the stored upper bound on expiry.

func (UploadForm) Fields

func (f UploadForm) Fields() []FormField

Fields returns an independent copy of the signed form fields.

func (UploadForm) FileField

func (UploadForm) FileField() string

FileField returns the field name used for file content.

func (UploadForm) Format

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

Format writes a label without exposing bearer credentials.

func (UploadForm) LogValue

func (UploadForm) LogValue() slog.Value

LogValue returns a label without exposing bearer credentials.

func (UploadForm) MarshalJSON

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

MarshalJSON rejects implicit export of bearer credentials.

func (UploadForm) String

func (UploadForm) String() string

String returns a label without exposing bearer credentials.

func (UploadForm) URL

func (f UploadForm) URL() string

URL explicitly returns the bearer upload form address.

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

Validate checks lifetime, media type and upload size bounds against maximum.

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)

NewUploadLink validates a signed PUT request, copies headers and normalizes expiry to UTC.

func (UploadLink) ExpiresAt

func (l UploadLink) ExpiresAt() time.Time

ExpiresAt returns the stored upper bound on expiry.

func (UploadLink) Format

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

Format writes a label without exposing bearer credentials.

func (UploadLink) Headers

func (l UploadLink) Headers() http.Header

Headers returns an independent copy of the signed request headers.

func (UploadLink) LogValue

func (UploadLink) LogValue() slog.Value

LogValue returns a label without exposing bearer credentials.

func (UploadLink) MarshalJSON

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

MarshalJSON rejects implicit export of bearer credentials.

func (UploadLink) Method

func (l UploadLink) Method() string

Method returns the signed request method.

func (UploadLink) String

func (UploadLink) String() string

String returns a label without exposing bearer credentials.

func (UploadLink) URL

func (l UploadLink) URL() string

URL explicitly returns the bearer upload request address.

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

Validate checks lifetime, media type and a positive size within maximum, rejecting replacement conditions.

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

Validate checks version length and control characters; an empty version is valid.

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
}

WriteCondition declares an atomic publication precondition; zero permits unconditional writes.

func IfAbsent

func IfAbsent() WriteCondition

IfAbsent requires the destination object to be absent when publishing.

func IfMatch

func IfMatch(tag ETag) (WriteCondition, error)

IfMatch validates a nonempty strong validator and requires it to match when publishing.

func (WriteCondition) Match

func (c WriteCondition) Match() ETag

Match returns the required validator, or an empty tag when none is required.

func (WriteCondition) RequiresAbsence

func (c WriteCondition) RequiresAbsence() bool

RequiresAbsence reports whether publication requires a missing destination.

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