Documentation
¶
Overview ¶
Package storage provides a unified file storage abstraction with local-disk and S3-compatible (AWS S3, MinIO, Wasabi, R2) drivers.
Index ¶
- Variables
- type Disk
- type Local
- func (l *Local) Copy(ctx context.Context, src, dst string) error
- func (l *Local) Delete(_ context.Context, path string) error
- func (l *Local) Exists(_ context.Context, path string) (bool, error)
- func (l *Local) Get(_ context.Context, path string) (io.ReadCloser, error)
- func (l *Local) List(_ context.Context, prefix string) ([]string, error)
- func (l *Local) Move(ctx context.Context, src, dst string) error
- func (l *Local) Put(_ context.Context, path string, r io.Reader, _ ...PutOptions) error
- func (l *Local) SignedURL(_ context.Context, _ string, _ time.Duration) (string, error)
- func (l *Local) Size(_ context.Context, path string) (int64, error)
- func (l *Local) URL(path string) string
- type Manager
- func (m *Manager) Delete(ctx context.Context, path string) error
- func (m *Manager) Disk(name string) Disk
- func (m *Manager) DiskErr(name string) (Disk, error)
- func (m *Manager) Get(ctx context.Context, path string) (io.ReadCloser, error)
- func (m *Manager) Put(ctx context.Context, path string, r io.Reader, opts ...PutOptions) error
- func (m *Manager) URL(path string) string
- type PutOptions
- type S3
- func (s *S3) Copy(ctx context.Context, src, dst string) error
- func (s *S3) Delete(ctx context.Context, path string) error
- func (s *S3) Exists(ctx context.Context, path string) (bool, error)
- func (s *S3) Get(ctx context.Context, path string) (io.ReadCloser, error)
- func (s *S3) List(ctx context.Context, prefix string) ([]string, error)
- func (s *S3) Move(ctx context.Context, src, dst string) error
- func (s *S3) Put(ctx context.Context, path string, r io.Reader, opts ...PutOptions) error
- func (s *S3) SignedURL(ctx context.Context, path string, ttl time.Duration) (string, error)
- func (s *S3) Size(ctx context.Context, path string) (int64, error)
- func (s *S3) URL(path string) string
- type S3Config
Constants ¶
This section is empty.
Variables ¶
var ErrSignedURLUnsupported = errors.New("storage: signed URLs are not supported by this driver")
ErrSignedURLUnsupported is returned by drivers that cannot produce pre-signed URLs.
Functions ¶
This section is empty.
Types ¶
type Disk ¶
type Disk interface {
// Put writes r to the given path, creating directories as needed.
Put(ctx context.Context, path string, r io.Reader, opts ...PutOptions) error
// Get returns a reader for the object at path.
Get(ctx context.Context, path string) (io.ReadCloser, error)
// Delete removes the object at path.
Delete(ctx context.Context, path string) error
// Exists reports whether an object exists at path.
Exists(ctx context.Context, path string) (bool, error)
// URL returns the public URL for path. For signed URLs, use SignedURL.
URL(path string) string
// SignedURL returns a pre-signed URL valid for ttl.
SignedURL(ctx context.Context, path string, ttl time.Duration) (string, error)
// List returns the keys under prefix.
List(ctx context.Context, prefix string) ([]string, error)
// Size returns the byte size of the object at path.
Size(ctx context.Context, path string) (int64, error)
// Copy duplicates src to dst within the same disk.
Copy(ctx context.Context, src, dst string) error
// Move renames src to dst within the same disk.
Move(ctx context.Context, src, dst string) error
}
Disk is the interface every storage driver must implement.
type Local ¶
type Local struct {
// contains filtered or unexported fields
}
Local is a local-disk storage driver.
func NewLocal ¶
NewLocal creates a local disk driver.
disk := storage.NewLocal("/var/app/storage", "https://example.com/storage")
type Manager ¶
type Manager struct {
Default string
// contains filtered or unexported fields
}
Manager holds named disk instances.
func NewManager ¶
NewManager creates a Manager with the given named disks.
func (*Manager) Disk ¶
Disk returns a named disk. It panics if the disk is not configured — use it only with names you registered at startup; prefer DiskErr when the name comes from config or user input.
func (*Manager) DiskErr ¶
DiskErr returns a named disk, or an error if no disk is registered under that name. This is the non-panicking counterpart of Disk.
type PutOptions ¶
type PutOptions struct {
ContentType string
ACL string // e.g. "public-read", "private"
Metadata map[string]string
}
PutOptions holds optional metadata for a Put operation.
type S3 ¶
type S3 struct {
// contains filtered or unexported fields
}
S3 is an S3-compatible storage driver.
type S3Config ¶
type S3Config struct {
Bucket string
Region string
AccessKeyID string
SecretAccessKey string
// Endpoint is the base URL for S3-compatible services (MinIO, Wasabi, R2).
// Leave empty for AWS S3.
Endpoint string
// BaseURL is the public CDN/bucket URL used by URL(). If empty, the S3 URL is used.
BaseURL string
// DefaultACL is the default ACL for new objects (default: "private").
DefaultACL string
// ForcePathStyle enables path-style addressing (required by MinIO).
ForcePathStyle bool
}
S3Config holds credentials and settings for an S3-compatible object store.