memory

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package memory is an in-process storage.Storage for tests: objects live in a map, nothing touches the filesystem, and every behavior is deterministic. It keeps the whole storage contract (it passes storagetest), but it buffers each object in memory, so it is not for large files or for production.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Store)

Option configures a Store.

func WithClock

func WithClock(now func() time.Time) Option

WithClock sets the clock that stamps ObjectInfo.ModTime (default time.Now), for tests that assert on it.

func WithURLs

func WithURLs(signer *presign.Signer) Option

WithURLs gives the store URLs, made by signer and served by presign.Handler (which the application mounts at signer.Path(); framework.New does). Without it, URL returns storage.ErrUnsupported.

type Store

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

Store is an in-memory storage.Storage. The zero value is not usable; call New. It is safe for concurrent use.

func New

func New(opts ...Option) *Store

New returns an empty in-memory store.

func (*Store) BoundedWrites

func (*Store) BoundedWrites()

BoundedWrites implements storage.BoundedWriter: a Put publishes in the process, after checking its context, within the call.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, key string) error

Delete implements storage.Storage.

func (*Store) Keys

func (s *Store) Keys() []string

Keys returns the stored keys, for tests that assert what was written. The order is unspecified.

func (*Store) List

func (s *Store) List(ctx context.Context, prefix string, fn func(storage.ObjectInfo) error) error

List implements storage.Lister, in key order, over a snapshot taken when it starts (fn may delete).

func (*Store) Open

Open implements storage.Storage.

func (*Store) Put

func (s *Store) Put(ctx context.Context, key string, r io.Reader, opts storage.PutOptions) (storage.ObjectInfo, error)

Put implements storage.Storage. The object is read completely before it replaces the old one, so a failed Put changes nothing.

func (*Store) Stat

func (s *Store) Stat(ctx context.Context, key string) (storage.ObjectInfo, error)

Stat implements storage.Storage.

func (*Store) URL

func (s *Store) URL(ctx context.Context, key string, opts storage.URLOptions) (string, error)

URL implements storage.Storage with the store's presign.Signer (WithURLs): a public URL for a key under its public prefix, or a signed one. Without a Signer it returns storage.ErrUnsupported (after validating its arguments).

func (*Store) UploadURL

func (s *Store) UploadURL(ctx context.Context, key string, opts storage.UploadURLOptions) (storage.UploadRequest, error)

UploadURL implements storage.DirectUploader with the store's presign.Signer (WithURLs): a signed PUT that presign.Handler stores. Without a Signer it returns storage.ErrUnsupported (after validating its arguments).

Jump to

Keyboard shortcuts

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