Documentation
¶
Index ¶
- Variables
- type Filesystem
- type FilesystemWithExtras
- type LocalDriver
- func (d *LocalDriver) Copy(source, destination string) error
- func (d *LocalDriver) Delete(path string) error
- func (d *LocalDriver) DeleteDirectory(path string) error
- func (d *LocalDriver) Directories(path string) ([]string, error)
- func (d *LocalDriver) Exists(path string) bool
- func (d *LocalDriver) Files(path string) ([]string, error)
- func (d *LocalDriver) Get(path string) ([]byte, error)
- func (d *LocalDriver) GetVisibility(path string) (string, error)
- func (d *LocalDriver) LastModified(path string) (time.Time, error)
- func (d *LocalDriver) MakeDirectory(path string) error
- func (d *LocalDriver) Move(source, destination string) error
- func (d *LocalDriver) Put(path string, contents []byte) error
- func (d *LocalDriver) SetVisibility(path string, visibility string) 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 LocalFilesystem
- func (l *LocalFilesystem) Delete(path string) error
- func (l *LocalFilesystem) Exists(path string) bool
- func (l *LocalFilesystem) Get(path string) ([]byte, error)
- func (l *LocalFilesystem) Put(path string, contents []byte) error
- func (l *LocalFilesystem) ReadStream(path string) (io.ReadCloser, error)
- type Manager
- type S3Driver
- func (d *S3Driver) Delete(path string) error
- func (d *S3Driver) Exists(path string) bool
- func (d *S3Driver) Get(path string) ([]byte, error)
- func (d *S3Driver) GetReader(path string) (io.ReadCloser, error)
- func (d *S3Driver) PresignedURL(path string, expiry time.Duration) (string, error)
- func (d *S3Driver) Put(path string, contents []byte) error
- func (d *S3Driver) PutReader(path string, contents io.Reader) error
- func (d *S3Driver) URL(path string) string
- type SFTPConfig
- type SFTPDriver
- func (d *SFTPDriver) Close() error
- func (d *SFTPDriver) Copy(source, destination string) error
- func (d *SFTPDriver) Delete(path string) error
- func (d *SFTPDriver) DeleteDirectory(path string) error
- func (d *SFTPDriver) Directories(path string) ([]string, error)
- func (d *SFTPDriver) Exists(path string) bool
- func (d *SFTPDriver) Files(path string) ([]string, error)
- func (d *SFTPDriver) Get(path string) ([]byte, error)
- func (d *SFTPDriver) GetVisibility(path string) (string, error)
- func (d *SFTPDriver) LastModified(path string) (time.Time, error)
- func (d *SFTPDriver) MakeDirectory(path string) error
- func (d *SFTPDriver) Move(source, destination string) error
- func (d *SFTPDriver) Put(path string, contents []byte) error
- func (d *SFTPDriver) SetVisibility(path string, visibility string) error
- func (d *SFTPDriver) Size(path string) (int64, error)
- func (d *SFTPDriver) TemporaryURL(path string, expiration time.Duration) (string, error)
- type UploadedFile
- func (u *UploadedFile) Contents() ([]byte, error)
- func (u *UploadedFile) GetClientExtension() string
- func (u *UploadedFile) GetClientMimeType() string
- func (u *UploadedFile) GetClientOriginalName() string
- func (u *UploadedFile) GetError() error
- func (u *UploadedFile) GetMimeType() string
- func (u *UploadedFile) GetSize() int64
- func (u *UploadedFile) IsValid() bool
- func (u *UploadedFile) Move(destination string) error
- func (u *UploadedFile) Store(filesystem Filesystem, path string) error
- func (u *UploadedFile) StoreAs(filesystem Filesystem, directory, name string) error
- func (u *UploadedFile) TemporaryURL(filesystem Filesystem, expiration time.Duration) (string, error)
Constants ¶
This section is empty.
Variables ¶
var ErrNotImplemented = errors.New("driver not implemented")
Functions ¶
This section is empty.
Types ¶
type Filesystem ¶
type Filesystem interface {
Put(path string, contents []byte) error
Get(path string) ([]byte, error)
Exists(path string) bool
Delete(path string) error
}
Filesystem defines the common interface for all storage drivers.
type FilesystemWithExtras ¶
type FilesystemWithExtras interface {
Filesystem
TemporaryURL(path string, expiration time.Duration) (string, error)
SetVisibility(path string, visibility string) error
GetVisibility(path string) (string, error)
Copy(source, destination string) error
Move(source, destination string) error
MakeDirectory(path string) error
DeleteDirectory(path string) error
Files(path string) ([]string, error)
Directories(path string) ([]string, error)
Size(path string) (int64, error)
LastModified(path string) (time.Time, error)
}
FilesystemWithExtras is an optional interface for drivers that support additional features.
type LocalDriver ¶
type LocalDriver struct {
RootPath string
BaseURL string
Visibility string // "public" or "private"
}
LocalDriver implements the Filesystem interface for the local filesystem.
func (*LocalDriver) Copy ¶
func (d *LocalDriver) Copy(source, destination string) error
Copy copies a file from source to destination.
func (*LocalDriver) Delete ¶
func (d *LocalDriver) Delete(path string) error
func (*LocalDriver) DeleteDirectory ¶
func (d *LocalDriver) DeleteDirectory(path string) error
DeleteDirectory deletes a directory and its contents.
func (*LocalDriver) Directories ¶
func (d *LocalDriver) Directories(path string) ([]string, error)
Directories returns all subdirectories in a directory.
func (*LocalDriver) Exists ¶
func (d *LocalDriver) Exists(path string) bool
func (*LocalDriver) Files ¶
func (d *LocalDriver) Files(path string) ([]string, error)
Files returns all files in a directory.
func (*LocalDriver) GetVisibility ¶
func (d *LocalDriver) GetVisibility(path string) (string, error)
GetVisibility returns the file visibility.
func (*LocalDriver) LastModified ¶
func (d *LocalDriver) LastModified(path string) (time.Time, error)
LastModified returns the last modification time.
func (*LocalDriver) MakeDirectory ¶
func (d *LocalDriver) MakeDirectory(path string) error
MakeDirectory creates a directory.
func (*LocalDriver) Move ¶
func (d *LocalDriver) Move(source, destination string) error
Move moves a file from source to destination.
func (*LocalDriver) SetVisibility ¶
func (d *LocalDriver) SetVisibility(path string, visibility string) error
SetVisibility sets the file visibility (public or private).
func (*LocalDriver) Size ¶
func (d *LocalDriver) Size(path string) (int64, error)
Size returns the file size in bytes.
func (*LocalDriver) TemporaryURL ¶
TemporaryURL returns a URL for the file (local driver just returns the regular URL).
func (*LocalDriver) URL ¶
func (d *LocalDriver) URL(path string) string
type LocalFilesystem ¶
type LocalFilesystem struct {
Root string
}
LocalFilesystem implements Filesystem for the local disk.
func NewLocalFilesystem ¶
func NewLocalFilesystem(root string) *LocalFilesystem
NewLocalFilesystem creates a new local filesystem driver.
func (*LocalFilesystem) Delete ¶
func (l *LocalFilesystem) Delete(path string) error
func (*LocalFilesystem) Exists ¶
func (l *LocalFilesystem) Exists(path string) bool
func (*LocalFilesystem) ReadStream ¶
func (l *LocalFilesystem) ReadStream(path string) (io.ReadCloser, error)
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages storage disks.
func (*Manager) Disk ¶
func (m *Manager) Disk(name string) Filesystem
Disk gets a registered disk by name.
func (*Manager) Extend ¶
func (m *Manager) Extend(name string, driver Filesystem)
Extend registers a custom driver implementation.
type S3Driver ¶
type S3Driver struct {
// contains filtered or unexported fields
}
S3Driver implements the Driver interface for Amazon S3 using AWS SDK v2.
func NewS3Driver ¶
NewS3Driver creates a new S3 driver. It supports loading credentials from environment variables or explicit keys.
func (*S3Driver) GetReader ¶
func (d *S3Driver) GetReader(path string) (io.ReadCloser, error)
GetReader returns an io.ReadCloser for streaming from S3.
func (*S3Driver) PresignedURL ¶
PresignedURL generates a temporary signed URL (useful for private files).
type SFTPConfig ¶
type SFTPConfig struct {
Host string
Port int
Username string
Password string
PrivateKey string
Passphrase string
BasePath string
Timeout time.Duration
}
SFTPConfig holds SFTP connection configuration.
type SFTPDriver ¶
type SFTPDriver struct {
// contains filtered or unexported fields
}
SFTPDriver provides SFTP filesystem access.
func NewSFTPDriver ¶
func NewSFTPDriver(config SFTPConfig) (*SFTPDriver, error)
NewSFTPDriver creates a new SFTP filesystem driver.
func (*SFTPDriver) Copy ¶
func (d *SFTPDriver) Copy(source, destination string) error
Copy copies a file within the SFTP server.
func (*SFTPDriver) Delete ¶
func (d *SFTPDriver) Delete(path string) error
Delete removes the file at the given path.
func (*SFTPDriver) DeleteDirectory ¶
func (d *SFTPDriver) DeleteDirectory(path string) error
DeleteDirectory removes a directory.
func (*SFTPDriver) Directories ¶
func (d *SFTPDriver) Directories(path string) ([]string, error)
Directories returns all subdirectories in a directory.
func (*SFTPDriver) Exists ¶
func (d *SFTPDriver) Exists(path string) bool
Exists checks if a file exists.
func (*SFTPDriver) Files ¶
func (d *SFTPDriver) Files(path string) ([]string, error)
Files returns a list of files in the given directory.
func (*SFTPDriver) Get ¶
func (d *SFTPDriver) Get(path string) ([]byte, error)
Get returns the file contents as bytes.
func (*SFTPDriver) GetVisibility ¶
func (d *SFTPDriver) GetVisibility(path string) (string, error)
GetVisibility returns the file visibility.
func (*SFTPDriver) LastModified ¶
func (d *SFTPDriver) LastModified(path string) (time.Time, error)
LastModified returns the last modification time.
func (*SFTPDriver) MakeDirectory ¶
func (d *SFTPDriver) MakeDirectory(path string) error
MakeDirectory creates a directory.
func (*SFTPDriver) Move ¶
func (d *SFTPDriver) Move(source, destination string) error
Move moves a file within the SFTP server.
func (*SFTPDriver) Put ¶
func (d *SFTPDriver) Put(path string, contents []byte) error
Put stores content at the given path.
func (*SFTPDriver) SetVisibility ¶
func (d *SFTPDriver) SetVisibility(path string, visibility string) error
SetVisibility sets the file visibility (no-op for SFTP).
func (*SFTPDriver) Size ¶
func (d *SFTPDriver) Size(path string) (int64, error)
Size returns the file size.
func (*SFTPDriver) TemporaryURL ¶
TemporaryURL is not supported for SFTP.
type UploadedFile ¶
type UploadedFile struct {
// contains filtered or unexported fields
}
UploadedFile represents a file uploaded via multipart form.
func NewUploadedFile ¶
func NewUploadedFile(file multipart.File, header *multipart.FileHeader) *UploadedFile
NewUploadedFile creates a new UploadedFile from a multipart file and header.
func (*UploadedFile) Contents ¶
func (u *UploadedFile) Contents() ([]byte, error)
Contents reads and returns the entire file contents.
func (*UploadedFile) GetClientExtension ¶
func (u *UploadedFile) GetClientExtension() string
GetClientExtension returns the file extension.
func (*UploadedFile) GetClientMimeType ¶
func (u *UploadedFile) GetClientMimeType() string
GetClientMimeType returns the MIME type of the uploaded file.
func (*UploadedFile) GetClientOriginalName ¶
func (u *UploadedFile) GetClientOriginalName() string
GetClientOriginalName returns the original name of the uploaded file.
func (*UploadedFile) GetError ¶
func (u *UploadedFile) GetError() error
GetError returns any error that occurred during upload.
func (*UploadedFile) GetMimeType ¶
func (u *UploadedFile) GetMimeType() string
GetMimeType returns the MIME type (alias for GetClientMimeType).
func (*UploadedFile) GetSize ¶
func (u *UploadedFile) GetSize() int64
GetSize returns the file size in bytes.
func (*UploadedFile) IsValid ¶
func (u *UploadedFile) IsValid() bool
IsValid returns true if the file was uploaded without errors.
func (*UploadedFile) Move ¶
func (u *UploadedFile) Move(destination string) error
Move moves the uploaded file to a new location.
func (*UploadedFile) Store ¶
func (u *UploadedFile) Store(filesystem Filesystem, path string) error
Store stores the uploaded file to the given filesystem path.
func (*UploadedFile) StoreAs ¶
func (u *UploadedFile) StoreAs(filesystem Filesystem, directory, name string) error
StoreAs stores the uploaded file with a specific name.
func (*UploadedFile) TemporaryURL ¶
func (u *UploadedFile) TemporaryURL(filesystem Filesystem, expiration time.Duration) (string, error)
TemporaryURL generates a temporary URL for the uploaded file.