Documentation
¶
Index ¶
- Variables
- func AllDirectories(directory string) ([]string, error)
- func AllFiles(directory string) ([]string, error)
- func Configure(config Config) error
- func Copy(from, to string) error
- func Delete(paths ...string) error
- func DeleteDirectory(directory string) error
- func Directories(directory string) ([]string, error)
- func Exists(path string) bool
- func Files(directory string) ([]string, error)
- func Get(path string) ([]byte, error)
- func GetStream(path string) (io.ReadCloser, error)
- func LastModified(path string) (time.Time, error)
- func MakeDirectory(path string) error
- func MimeType(path string) (string, error)
- func Move(from, to string) error
- func Put(path string, contents []byte) error
- func PutStream(path string, stream io.Reader) error
- func ReloadFromEnv()
- func SetGlobalManager(manager *Manager)
- func Size(path string) (int64, error)
- func TemporaryURL(path string, expiration time.Duration) (string, error)
- func URL(path string) string
- type Config
- type DiskConfig
- type Driver
- type FileInfo
- type LocalDriver
- func (d *LocalDriver) AllDirectories(directory string) ([]string, error)
- func (d *LocalDriver) AllFiles(directory string) ([]string, error)
- func (d *LocalDriver) Copy(from, to string) error
- func (d *LocalDriver) Delete(paths ...string) error
- func (d *LocalDriver) DeleteDirectory(directory string) error
- func (d *LocalDriver) Directories(directory string) ([]string, error)
- func (d *LocalDriver) Exists(path string) bool
- func (d *LocalDriver) Files(directory string) ([]string, error)
- func (d *LocalDriver) Get(path string) ([]byte, error)
- func (d *LocalDriver) GetStream(path string) (io.ReadCloser, error)
- func (d *LocalDriver) LastModified(path string) (time.Time, error)
- func (d *LocalDriver) MakeDirectory(path string) error
- func (d *LocalDriver) MimeType(path string) (string, error)
- func (d *LocalDriver) Move(from, to string) error
- func (d *LocalDriver) Put(path string, contents []byte) error
- func (d *LocalDriver) PutStream(path string, stream io.Reader) error
- func (d *LocalDriver) Size(path string) (int64, error)
- func (d *LocalDriver) TemporaryURL(path string, expiration time.Duration) (string, error)
- func (d *LocalDriver) URL(path string) string
- type Manager
- type MemoryDriver
- func (d *MemoryDriver) AllDirectories(directory string) ([]string, error)
- func (d *MemoryDriver) AllFiles(directory string) ([]string, error)
- func (d *MemoryDriver) Clear()
- func (d *MemoryDriver) Copy(from, to string) error
- func (d *MemoryDriver) Delete(paths ...string) error
- func (d *MemoryDriver) DeleteDirectory(directory string) error
- func (d *MemoryDriver) Directories(directory string) ([]string, error)
- func (d *MemoryDriver) Exists(path string) bool
- func (d *MemoryDriver) Files(directory string) ([]string, error)
- func (d *MemoryDriver) Get(path string) ([]byte, error)
- func (d *MemoryDriver) GetStream(path string) (io.ReadCloser, error)
- func (d *MemoryDriver) LastModified(path string) (time.Time, error)
- func (d *MemoryDriver) MakeDirectory(path string) error
- func (d *MemoryDriver) MimeType(path string) (string, error)
- func (d *MemoryDriver) Move(from, to string) error
- func (d *MemoryDriver) Put(path string, contents []byte) error
- func (d *MemoryDriver) PutStream(path string, stream io.Reader) error
- func (d *MemoryDriver) Size(path string) (int64, error)
- func (d *MemoryDriver) Stats() (used int64, max int64, fileCount int)
- func (d *MemoryDriver) TemporaryURL(path string, expiration time.Duration) (string, error)
- func (d *MemoryDriver) URL(path string) string
- type MemoryFile
- type Option
- type PutOptions
- type S3Driver
- func (d *S3Driver) AllDirectories(directory string) ([]string, error)
- func (d *S3Driver) AllFiles(directory string) ([]string, error)
- func (d *S3Driver) Copy(from, to string) error
- func (d *S3Driver) Delete(paths ...string) error
- func (d *S3Driver) DeleteDirectory(directory string) error
- func (d *S3Driver) Directories(directory string) ([]string, error)
- func (d *S3Driver) Exists(path string) bool
- func (d *S3Driver) Files(directory string) ([]string, error)
- func (d *S3Driver) Get(path string) ([]byte, error)
- func (d *S3Driver) GetStream(path string) (io.ReadCloser, error)
- func (d *S3Driver) LastModified(path string) (time.Time, error)
- func (d *S3Driver) MakeDirectory(path string) error
- func (d *S3Driver) MimeType(path string) (string, error)
- func (d *S3Driver) Move(from, to string) error
- func (d *S3Driver) Put(path string, contents []byte) error
- func (d *S3Driver) PutStream(path string, stream io.Reader) error
- func (d *S3Driver) Size(path string) (int64, error)
- func (d *S3Driver) TemporaryURL(path string, expiration time.Duration) (string, error)
- func (d *S3Driver) URL(path string) string
- type Visibility
Constants ¶
This section is empty.
Variables ¶
var ( ErrFileNotFound = errors.New("file not found") ErrDiskNotFound = errors.New("disk not found") ErrInvalidPath = errors.New("invalid file path") ErrQuotaExceeded = errors.New("storage quota exceeded") ErrAccessDenied = errors.New("access denied") ErrNotSupported = errors.New("operation not supported by this driver") )
Common errors
Functions ¶
func AllDirectories ¶
AllDirectories lists all directories recursively using the default disk
func DeleteDirectory ¶
DeleteDirectory deletes a directory using the default disk
func Directories ¶
Directories lists directories using the default disk
func GetStream ¶
func GetStream(path string) (io.ReadCloser, error)
GetStream retrieves a stream from the given path using the default disk
func LastModified ¶
LastModified returns the last modified time of a file using the default disk
func MakeDirectory ¶
MakeDirectory creates a directory using the default disk
func ReloadFromEnv ¶
func ReloadFromEnv()
ReloadFromEnv reloads storage configuration from environment Useful for testing or runtime reconfiguration
func SetGlobalManager ¶
func SetGlobalManager(manager *Manager)
SetGlobalManager sets the global storage manager (mainly for testing)
func TemporaryURL ¶
TemporaryURL returns a temporary URL for a file using the default disk
Types ¶
type Config ¶
type Config struct {
Default string // Default disk name
Disks map[string]DiskConfig // Configured disks
}
Config holds storage configuration
type DiskConfig ¶
type DiskConfig struct {
Driver string // "local", "s3", "memory"
// Local driver config
Root string // Root directory for local storage
URL string // Base URL for file access
Visibility string // Default visibility (public/private)
// S3 driver config
Key string // AWS Access Key
Secret string // AWS Secret Key
Region string // AWS Region
Bucket string // S3 Bucket name
// Memory driver config
MaxSize int64 // Maximum memory usage in bytes
}
DiskConfig holds configuration for a storage disk
type Driver ¶
type Driver interface {
// Basic operations
Put(path string, contents []byte) error
PutStream(path string, stream io.Reader) error
Get(path string) ([]byte, error)
GetStream(path string) (io.ReadCloser, error)
// File management
Exists(path string) bool
Delete(paths ...string) error
Copy(from, to string) error
Move(from, to string) error
// File information
Size(path string) (int64, error)
LastModified(path string) (time.Time, error)
MimeType(path string) (string, error)
// Directory operations
Files(directory string) ([]string, error)
AllFiles(directory string) ([]string, error)
Directories(directory string) ([]string, error)
AllDirectories(directory string) ([]string, error)
MakeDirectory(path string) error
DeleteDirectory(directory string) error
// URL operations
URL(path string) string
TemporaryURL(path string, expiration time.Duration) (string, error)
}
Driver defines the storage driver interface
type FileInfo ¶
type FileInfo struct {
Path string
Size int64
LastModified time.Time
MimeType string
Visibility Visibility
}
FileInfo contains file metadata
type LocalDriver ¶
type LocalDriver struct {
// contains filtered or unexported fields
}
LocalDriver implements the Driver interface for local filesystem storage
func NewLocalDriver ¶
func NewLocalDriver(config DiskConfig) *LocalDriver
NewLocalDriver creates a new local storage driver
func (*LocalDriver) AllDirectories ¶
func (d *LocalDriver) AllDirectories(directory string) ([]string, error)
AllDirectories lists all directories recursively
func (*LocalDriver) AllFiles ¶
func (d *LocalDriver) AllFiles(directory string) ([]string, error)
AllFiles lists all files recursively in a directory
func (*LocalDriver) Copy ¶
func (d *LocalDriver) Copy(from, to string) error
Copy copies a file from one path to another
func (*LocalDriver) Delete ¶
func (d *LocalDriver) Delete(paths ...string) error
Delete removes files at the given paths
func (*LocalDriver) DeleteDirectory ¶
func (d *LocalDriver) DeleteDirectory(directory string) error
DeleteDirectory deletes a directory and all its contents
func (*LocalDriver) Directories ¶
func (d *LocalDriver) Directories(directory string) ([]string, error)
Directories lists directories
func (*LocalDriver) Exists ¶
func (d *LocalDriver) Exists(path string) bool
Exists checks if a file exists at the given path
func (*LocalDriver) Files ¶
func (d *LocalDriver) Files(directory string) ([]string, error)
Files lists files in a directory
func (*LocalDriver) Get ¶
func (d *LocalDriver) Get(path string) ([]byte, error)
Get retrieves content from the given path
func (*LocalDriver) GetStream ¶
func (d *LocalDriver) GetStream(path string) (io.ReadCloser, error)
GetStream retrieves a stream from the given path
func (*LocalDriver) LastModified ¶
func (d *LocalDriver) LastModified(path string) (time.Time, error)
LastModified returns the last modified time of a file
func (*LocalDriver) MakeDirectory ¶
func (d *LocalDriver) MakeDirectory(path string) error
MakeDirectory creates a directory
func (*LocalDriver) MimeType ¶
func (d *LocalDriver) MimeType(path string) (string, error)
MimeType returns the MIME type of a file
func (*LocalDriver) Move ¶
func (d *LocalDriver) Move(from, to string) error
Move moves a file from one path to another
func (*LocalDriver) Put ¶
func (d *LocalDriver) Put(path string, contents []byte) error
Put stores content at the given path
func (*LocalDriver) PutStream ¶
func (d *LocalDriver) PutStream(path string, stream io.Reader) error
PutStream stores a stream at the given path
func (*LocalDriver) Size ¶
func (d *LocalDriver) Size(path string) (int64, error)
Size returns the size of a file at the given path
func (*LocalDriver) TemporaryURL ¶
TemporaryURL returns a temporary URL for a file (not supported for local)
func (*LocalDriver) URL ¶
func (d *LocalDriver) URL(path string) string
URL returns the public URL for a file
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages multiple storage disks
func (*Manager) SetDefault ¶
SetDefault sets the default disk
type MemoryDriver ¶
type MemoryDriver struct {
// contains filtered or unexported fields
}
MemoryDriver implements the Driver interface for in-memory storage
func NewMemoryDriver ¶
func NewMemoryDriver(config DiskConfig) *MemoryDriver
NewMemoryDriver creates a new memory storage driver
func (*MemoryDriver) AllDirectories ¶
func (d *MemoryDriver) AllDirectories(directory string) ([]string, error)
AllDirectories lists all directories recursively
func (*MemoryDriver) AllFiles ¶
func (d *MemoryDriver) AllFiles(directory string) ([]string, error)
AllFiles lists all files recursively in a directory
func (*MemoryDriver) Copy ¶
func (d *MemoryDriver) Copy(from, to string) error
Copy copies a file from one path to another
func (*MemoryDriver) Delete ¶
func (d *MemoryDriver) Delete(paths ...string) error
Delete removes files at the given paths
func (*MemoryDriver) DeleteDirectory ¶
func (d *MemoryDriver) DeleteDirectory(directory string) error
DeleteDirectory deletes a directory and all its contents
func (*MemoryDriver) Directories ¶
func (d *MemoryDriver) Directories(directory string) ([]string, error)
Directories lists directories
func (*MemoryDriver) Exists ¶
func (d *MemoryDriver) Exists(path string) bool
Exists checks if a file exists at the given path
func (*MemoryDriver) Files ¶
func (d *MemoryDriver) Files(directory string) ([]string, error)
Files lists files in a directory
func (*MemoryDriver) Get ¶
func (d *MemoryDriver) Get(path string) ([]byte, error)
Get retrieves content from the given path
func (*MemoryDriver) GetStream ¶
func (d *MemoryDriver) GetStream(path string) (io.ReadCloser, error)
GetStream retrieves a stream from the given path
func (*MemoryDriver) LastModified ¶
func (d *MemoryDriver) LastModified(path string) (time.Time, error)
LastModified returns the last modified time of a file
func (*MemoryDriver) MakeDirectory ¶
func (d *MemoryDriver) MakeDirectory(path string) error
MakeDirectory creates a directory (no-op for memory driver)
func (*MemoryDriver) MimeType ¶
func (d *MemoryDriver) MimeType(path string) (string, error)
MimeType returns the MIME type of a file
func (*MemoryDriver) Move ¶
func (d *MemoryDriver) Move(from, to string) error
Move moves a file from one path to another
func (*MemoryDriver) Put ¶
func (d *MemoryDriver) Put(path string, contents []byte) error
Put stores content at the given path
func (*MemoryDriver) PutStream ¶
func (d *MemoryDriver) PutStream(path string, stream io.Reader) error
PutStream stores a stream at the given path
func (*MemoryDriver) Size ¶
func (d *MemoryDriver) Size(path string) (int64, error)
Size returns the size of a file at the given path
func (*MemoryDriver) Stats ¶
func (d *MemoryDriver) Stats() (used int64, max int64, fileCount int)
Stats returns memory usage statistics
func (*MemoryDriver) TemporaryURL ¶
TemporaryURL returns a temporary URL for a file (not supported for memory)
func (*MemoryDriver) URL ¶
func (d *MemoryDriver) URL(path string) string
URL returns the public URL for a file (not supported for memory)
type MemoryFile ¶
MemoryFile represents a file in memory
type Option ¶
type Option func(*PutOptions)
Option is a function that modifies PutOptions
func WithMetadata ¶
WithMetadata sets metadata for a file
func WithMimeType ¶
WithMimeType sets the MIME type for a file
func WithVisibility ¶
func WithVisibility(v Visibility) Option
WithVisibility sets the visibility for a file
type PutOptions ¶
type PutOptions struct {
Visibility Visibility
MimeType string
Metadata map[string]string
}
PutOptions contains options for Put operations
type S3Driver ¶
type S3Driver struct {
// contains filtered or unexported fields
}
S3Driver implements the Driver interface for AWS S3 storage
func NewS3Driver ¶
func NewS3Driver(config DiskConfig) (*S3Driver, error)
NewS3Driver creates a new S3 storage driver
func (*S3Driver) AllDirectories ¶
AllDirectories lists all directories recursively
func (*S3Driver) DeleteDirectory ¶
DeleteDirectory deletes a directory and all its contents
func (*S3Driver) Directories ¶
Directories lists directories
func (*S3Driver) GetStream ¶
func (d *S3Driver) GetStream(path string) (io.ReadCloser, error)
GetStream retrieves a stream from the given path
func (*S3Driver) LastModified ¶
LastModified returns the last modified time of a file
func (*S3Driver) MakeDirectory ¶
MakeDirectory creates a directory (no-op for S3)
func (*S3Driver) TemporaryURL ¶
TemporaryURL returns a temporary URL for a file
type Visibility ¶
type Visibility string
Visibility defines file visibility
const ( Public Visibility = "public" Private Visibility = "private" )