storage

package
v0.0.0-20260608 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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) Get

func (d *LocalDriver) Get(path string) ([]byte, error)

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) Put

func (d *LocalDriver) Put(path string, contents []byte) error

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

func (d *LocalDriver) TemporaryURL(path string, expiration time.Duration) (string, error)

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) Get

func (l *LocalFilesystem) Get(path string) ([]byte, error)

func (*LocalFilesystem) Put

func (l *LocalFilesystem) Put(path string, contents []byte) error

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 NewManager

func NewManager() *Manager

NewManager creates a new Storage manager.

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

func NewS3Driver(bucket, region, accessKey, secretKey string) (*S3Driver, error)

NewS3Driver creates a new S3 driver. It supports loading credentials from environment variables or explicit keys.

func (*S3Driver) Delete

func (d *S3Driver) Delete(path string) error

func (*S3Driver) Exists

func (d *S3Driver) Exists(path string) bool

func (*S3Driver) Get

func (d *S3Driver) Get(path string) ([]byte, error)

func (*S3Driver) GetReader

func (d *S3Driver) GetReader(path string) (io.ReadCloser, error)

GetReader returns an io.ReadCloser for streaming from S3.

func (*S3Driver) PresignedURL

func (d *S3Driver) PresignedURL(path string, expiry time.Duration) (string, error)

PresignedURL generates a temporary signed URL (useful for private files).

func (*S3Driver) Put

func (d *S3Driver) Put(path string, contents []byte) error

func (*S3Driver) PutReader

func (d *S3Driver) PutReader(path string, contents io.Reader) error

PutReader uploads data from an io.Reader to S3.

func (*S3Driver) URL

func (d *S3Driver) URL(path string) string

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) Close

func (d *SFTPDriver) Close() error

Close closes the SFTP connection.

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

func (d *SFTPDriver) TemporaryURL(path string, expiration time.Duration) (string, error)

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.

Jump to

Keyboard shortcuts

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