storage

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultDriver = "local"

	DiskLocal   = "local"
	DiskPublic  = "public"
	DiskPrivate = "private"
	DiskCloud   = "cloud"
)

Variables

This section is empty.

Functions

func Provider

func Provider(options ...ProviderOption) runaprovider.Provider

Provider creates a storage provider.

Types

type CopyDriver added in v0.1.3

type CopyDriver interface {
	Copy(ctx context.Context, from string, to string, options FileOptions) error
}

CopyDriver is implemented by drivers that can copy objects without routing data through the app.

type Disk

type Disk interface {
	Put(ctx context.Context, path string, body io.Reader, options ...FileOption) error
	PutBytes(ctx context.Context, path string, data []byte, options ...FileOption) error
	PutString(ctx context.Context, path string, data string, options ...FileOption) error

	Get(ctx context.Context, path string) (io.ReadCloser, FileInfo, error)
	GetBytes(ctx context.Context, path string) ([]byte, error)
	GetString(ctx context.Context, path string) (string, error)

	Delete(ctx context.Context, paths ...string) error
	Exists(ctx context.Context, path string) (bool, error)
	Size(ctx context.Context, path string) (int64, error)
	Info(ctx context.Context, path string) (FileInfo, error)
	List(ctx context.Context, prefix string, options ...ListOption) (FileList, error)
	Copy(ctx context.Context, from string, to string, options ...FileOption) error
	Move(ctx context.Context, from string, to string, options ...FileOption) error

	URL(ctx context.Context, path string) (string, error)
	TempURL(ctx context.Context, path string, ttl time.Duration) (string, error)
	SignPut(ctx context.Context, path string, ttl time.Duration, options ...FileOption) (SignedURL, error)
	SignPost(ctx context.Context, path string, ttl time.Duration, options ...FileOption) (SignedPost, error)
}

Disk is the business-facing named filesystem.

type DiskOption

type DiskOption interface {
	ApplyDisk(*DiskOptions)
}

DiskOption configures a named disk.

func Domain

func Domain(value string) DiskOption

Domain sets the public domain for this disk.

func Meta

func Meta(key string, value any) DiskOption

Meta stores arbitrary disk metadata.

func Prefix

func Prefix(value string) DiskOption

Prefix sets a disk or driver path prefix.

func Private

func Private() DiskOption

Private marks a disk as private.

func Public

func Public() DiskOption

Public marks a disk as publicly addressable.

func URLPrefix

func URLPrefix(value string) DiskOption

URLPrefix sets the public URL prefix for this disk.

func Use

func Use(name string) DiskOption

Driver selects the storage driver used by a disk.

type DiskOptions

type DiskOptions struct {
	Driver    string
	Prefix    string
	Public    bool
	URLPrefix string
	Domain    string
	Meta      core.Map
}

DiskOptions stores named disk configuration.

type Driver

type Driver interface {
	Name() string
	Put(ctx context.Context, path string, body io.Reader, options FileOptions) error
	Get(ctx context.Context, path string) (io.ReadCloser, FileInfo, error)
	Delete(ctx context.Context, paths ...string) error
	Exists(ctx context.Context, path string) (bool, error)
	Info(ctx context.Context, path string) (FileInfo, error)
	List(ctx context.Context, prefix string, options ListOptions) (FileList, error)
	URL(ctx context.Context, path string, options URLOptions) (string, error)
	TempURL(ctx context.Context, path string, ttl time.Duration, options URLOptions) (string, error)
	SignPut(ctx context.Context, path string, ttl time.Duration, options FileOptions) (SignedURL, error)
	SignPost(ctx context.Context, path string, ttl time.Duration, options FileOptions) (SignedPost, error)
	Close(ctx context.Context) error
}

Driver is the low-level storage adapter.

func LocalDriver

func LocalDriver(options ...DriverOption) Driver

LocalDriver creates a local filesystem storage driver.

type DriverOption

type DriverOption interface {
	ApplyDriver(*DriverOptions)
}

DriverOption configures local or external driver wrappers.

func DriverDomain

func DriverDomain(value string) DriverOption

DriverDomain sets local driver URL domain.

func DriverMeta

func DriverMeta(key string, value any) DriverOption

DriverMeta stores arbitrary driver metadata.

func DriverURLPrefix

func DriverURLPrefix(value string) DriverOption

DriverURLPrefix sets local driver URL prefix.

func Name

func Name(value string) DriverOption

Name sets driver name metadata.

func Root

func Root(value string) DriverOption

Root sets local driver root path.

func Secret

func Secret(value string) DriverOption

Secret sets signing secret for drivers that support signed URLs.

type DriverOptions

type DriverOptions struct {
	Name      string
	Root      string
	Domain    string
	URLPrefix string
	Secret    string
	Meta      core.Map
}

DriverOptions stores low-level driver configuration.

type FileInfo

type FileInfo struct {
	Path         string
	Size         int64
	ContentType  string
	ETag         string
	LastModified time.Time
	Meta         core.Map
}

FileInfo describes one stored object.

type FileList added in v0.1.3

type FileList struct {
	Items      []FileInfo
	Cursor     string
	HasMore    bool
	CommonDirs []string
}

FileList stores one page of listed objects.

type FileOption

type FileOption interface {
	ApplyFile(*FileOptions)
}

FileOption configures one file operation.

func ContentType

func ContentType(value string) FileOption

ContentType sets content type for one write/sign operation.

func FileMeta

func FileMeta(key string, value any) FileOption

FileMeta stores arbitrary file operation metadata.

type FileOptions

type FileOptions struct {
	ContentType string
	Meta        core.Map
}

FileOptions stores file operation metadata.

type Info

type Info struct {
	Name    string
	Driver  string
	Prefix  string
	Public  bool
	Default bool
	Meta    core.Map
}

Info describes one configured disk.

type ListOption added in v0.1.3

type ListOption interface {
	ApplyList(*ListOptions)
}

ListOption configures one list operation.

func Cursor added in v0.1.3

func Cursor(value string) ListOption

Cursor continues a paginated listing from a previous cursor.

func Limit added in v0.1.3

func Limit(value int32) ListOption

Limit sets the maximum number of objects returned by one list call.

func Recursive added in v0.1.3

func Recursive() ListOption

Recursive lists all nested objects under the prefix.

type ListOptions added in v0.1.3

type ListOptions struct {
	Cursor    string
	Limit     int32
	Recursive bool
}

ListOptions stores object listing controls.

type MoveDriver added in v0.1.3

type MoveDriver interface {
	Move(ctx context.Context, from string, to string, options FileOptions) error
}

MoveDriver is implemented by drivers that can move objects without routing data through the app.

type ProviderOption

type ProviderOption func(*provider)

ProviderOption configures a storage provider.

func RegisterDisk

func RegisterDisk(name string, options ...DiskOption) ProviderOption

RegisterDisk registers a named storage disk.

func RegisterDriver

func RegisterDriver(name string, driver Driver) ProviderOption

RegisterDriver registers a low-level storage driver.

type Registry

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

Registry stores storage drivers and named disks.

func Default

func Default() *Registry

Default returns the default app storage registry.

func New

func New(options ...DriverOption) *Registry

New creates a storage registry with default disk names.

func (*Registry) Close

func (registry *Registry) Close(ctx context.Context) error

Close closes all registered drivers once.

func (*Registry) Config

func (registry *Registry) Config(store *config.Store)

Config applies file/env config to already registered disks.

func (*Registry) Disk

func (registry *Registry) Disk(name string, options ...DiskOption)

Disk registers or replaces a named disk.

func (*Registry) Driver

func (registry *Registry) Driver(name string) Driver

Driver returns a registered driver by name.

func (*Registry) Info

func (registry *Registry) Info() []Info

Info returns configured disk snapshots.

func (*Registry) MustOf

func (registry *Registry) MustOf(name string) Disk

MustOf returns a named disk or panics.

func (*Registry) Of

func (registry *Registry) Of(name string) (Disk, error)

Of returns a named disk.

func (*Registry) RegisterDriver

func (registry *Registry) RegisterDriver(name string, driver Driver)

RegisterDriver registers a storage driver.

func (*Registry) Shutdown

func (registry *Registry) Shutdown(ctx context.Context) error

Shutdown closes all storage drivers when managed by DI.

type SignedPost

type SignedPost struct {
	URL     string
	Fields  map[string]string
	Expires time.Time
}

SignedPost describes a pre-signed form post.

type SignedURL

type SignedURL struct {
	URL     string
	Method  string
	Header  map[string]string
	Expires time.Time
}

SignedURL describes a pre-signed request URL.

type URLOptions

type URLOptions struct {
	Public    bool
	Prefix    string
	URLPrefix string
	Domain    string
	Meta      core.Map
}

URLOptions stores URL generation options.

Directories

Path Synopsis
s3 module

Jump to

Keyboard shortcuts

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