storage

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnsupported = errors.New("storage operation is not supported by this adapter")
	ErrNotFound    = errors.New("object not found")
)

Functions

This section is empty.

Types

type Inspector

type Inspector interface {
	Stat(ctx context.Context, key string) (StoredObject, error)
}

type Local

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

func NewLocal

func NewLocal(root, publicURL string) *Local

func (*Local) Delete

func (l *Local) Delete(ctx context.Context, key string) error

func (*Local) Get

func (l *Local) Get(ctx context.Context, key string) (Object, error)

func (*Local) Put

func (l *Local) Put(ctx context.Context, object Object) error

func (*Local) SignedURL

func (l *Local) SignedURL(_ context.Context, key string, ttl time.Duration) (string, error)

func (*Local) Stat

func (l *Local) Stat(ctx context.Context, key string) (StoredObject, error)

type Memory

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

Memory is a thread-safe in-memory storage adapter, primarily for tests.

func NewMemory

func NewMemory(publicURL string) *Memory

NewMemory creates a new in-memory storage backend. publicURL is an optional base URL used to build object URLs (can be empty).

func (*Memory) Delete

func (m *Memory) Delete(_ context.Context, key string) error

func (*Memory) Get

func (m *Memory) Get(_ context.Context, key string) (Object, error)

func (*Memory) Len

func (m *Memory) Len() int

Len returns the number of stored objects.

func (*Memory) Put

func (m *Memory) Put(_ context.Context, object Object) error

func (*Memory) SignedURL

func (m *Memory) SignedURL(_ context.Context, key string, ttl time.Duration) (string, error)

func (*Memory) Stat

func (m *Memory) Stat(_ context.Context, key string) (StoredObject, error)

type Object

type Object struct {
	Key         string
	Reader      io.Reader
	ContentType string
	Size        int64
	Private     bool
	Metadata    map[string]string
}

type S3Config

type S3Config struct {
	Endpoint        string
	Region          string
	Bucket          string
	AccessKeyID     string
	SecretAccessKey string
	PublicBaseURL   string
	ForcePathStyle  bool
}

type S3Store

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

S3Store implements Storage and Inspector for any S3-compatible object store (AWS S3, Cloudflare R2, MinIO, etc.) using only the standard library. Authentication uses AWS Signature Version 4.

func NewS3

func NewS3(config S3Config) (*S3Store, error)

NewS3 creates an S3Store from the provided config. Region defaults to "us-east-1" when empty. ForcePathStyle or a non-empty Endpoint both enable path-style URLs.

func (*S3Store) Delete

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

func (*S3Store) Get

func (s *S3Store) Get(ctx context.Context, key string) (Object, error)

func (*S3Store) Put

func (s *S3Store) Put(ctx context.Context, object Object) error

func (*S3Store) SignedURL

func (s *S3Store) SignedURL(_ context.Context, key string, ttl time.Duration) (string, error)

SignedURL returns a presigned GET URL valid for the given TTL. The URL allows unauthenticated download of a private object.

func (*S3Store) Stat

func (s *S3Store) Stat(ctx context.Context, key string) (StoredObject, error)

type Storage

type Storage interface {
	Put(ctx context.Context, object Object) error
	Get(ctx context.Context, key string) (Object, error)
	Delete(ctx context.Context, key string) error
	SignedURL(ctx context.Context, key string, ttl time.Duration) (string, error)
}

type StoredObject

type StoredObject struct {
	Key         string    `json:"key"`
	ContentType string    `json:"content_type"`
	Size        int64     `json:"size"`
	Private     bool      `json:"private"`
	URL         string    `json:"url,omitempty"`
	CreatedAt   time.Time `json:"created_at"`
}

Jump to

Keyboard shortcuts

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