Documentation
¶
Overview ¶
Package storage defines the object-store seam. The Backend interface is the only contract the rest of the system knows about; concrete implementations (see storage/s3) are injected at the composition root.
Index ¶
Constants ¶
const DefaultReadWindow = 1 << 20
DefaultReadWindow is the read-ahead length NewReaderAt uses when the caller passes a non-positive window. 1 MiB covers archive/zip's 65 KiB tail backscan and the whole central directory of any realistic document archive in a single range request.
Variables ¶
var ErrNotFound = errors.New("storage: object not found")
ErrNotFound is returned by a Backend when no object exists for the given key.
Functions ¶
func NewReaderAt ¶ added in v1.3.0
NewReaderAt returns an io.ReaderAt over the object at key. size must be the object's exact length — the caller has it from the metadata row, so no Stat round-trip is needed. window is the read-ahead length (DefaultReadWindow if non-positive): a cache miss fetches [off, off+window), or the object's final window bytes when off lies within one window of the end, so a tail-first reader like archive/zip is served from a single request.
ctx is captured, against the usual convention, because io.ReaderAt has no context parameter. The reader is scoped to one request and dies with it.
The returned reader honours the io.ReaderAt contract: ReadAt fills p or returns a non-nil error, with io.EOF exactly at the object's end. It is safe for concurrent use; calls are serialised.
Types ¶
type Backend ¶
type Backend interface {
// Put stores r under key. size is the exact content length (-1 if unknown,
// which forces the backend into a buffered/multipart path).
Put(ctx context.Context, key string, r io.Reader, size int64, contentType string) error
// Get returns a reader over the whole object. The caller must Close it.
Get(ctx context.Context, key string) (io.ReadCloser, error)
// GetRange returns a reader over [offset, offset+length). A length <= 0
// means "to end of object". The caller must Close it.
GetRange(ctx context.Context, key string, offset, length int64) (io.ReadCloser, error)
// Delete removes the object. Deleting a missing key is not an error.
Delete(ctx context.Context, key string) error
// List enumerates every stored object, invoking fn for each. It stops and
// returns fn's error if fn fails, and honors context cancellation. Used by
// GC reconciliation; not on the request path.
List(ctx context.Context, fn func(StoredObject) error) error
// Stat returns object metadata without transferring the body.
Stat(ctx context.Context, key string) (ObjectInfo, error)
// PresignGet returns a time-limited URL that downloads the object directly
// from the store, bypassing this service.
PresignGet(ctx context.Context, key string, ttl time.Duration) (string, error)
// PresignPut returns a time-limited URL that uploads directly to the store.
PresignPut(ctx context.Context, key string, ttl time.Duration) (string, error)
}
Backend is an S3-compatible object store. All methods stream; callers must never assume an object fits in memory. The context is honored on every call, including cancellation mid-stream.
type ObjectInfo ¶
ObjectInfo is the subset of object attributes the service cares about.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package memory is an in-memory storage.Backend used as a test double.
|
Package memory is an in-memory storage.Backend used as a test double. |
|
Package s3 is the minio-go implementation of storage.Backend.
|
Package s3 is the minio-go implementation of storage.Backend. |