storage

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const FilesTable = "_supacraft_files"

FilesTable records every upload in the tenant's own database. Remote drivers store files at the bucket (or directory) root with nothing that marks them as the tenant's, so purging a tenant deletes exactly these. Project validation reserves the "_supacraft_" table prefix.

Variables

This section is empty.

Functions

func Destination added in v0.3.0

func Destination(driver string, cfg map[string]any) string

Destination identifies where a driver configuration stores files, so a purge after the storage settings changed knows which records it can delete. It is the driver name plus a hash of the location (bucket, host, root...): the location may come from a secret and is not stored.

func DriverOf added in v0.3.0

func DriverOf(destination string) string

DriverOf is the driver name of a destination.

func TrackUpload added in v0.3.0

func TrackUpload(ctx context.Context, db Execer, path, destination string) error

TrackUpload records path before the file is written, so a file can't exist in storage without a record.

func UntrackUpload added in v0.3.0

func UntrackUpload(ctx context.Context, db Execer, path, destination string) error

UntrackUpload forgets path after it is deleted (or failed to upload).

Types

type AzureDriver

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

func NewAzureDriver

func NewAzureDriver(cfg map[string]any) (*AzureDriver, error)

func (*AzureDriver) Delete

func (d *AzureDriver) Delete(ctx context.Context, path string) error

func (*AzureDriver) Exists

func (d *AzureDriver) Exists(ctx context.Context, path string) (bool, error)

func (*AzureDriver) Get

func (d *AzureDriver) Get(ctx context.Context, path string) (io.ReadCloser, error)

func (*AzureDriver) Put

func (d *AzureDriver) Put(ctx context.Context, path string, reader io.Reader, _ int64) error

type Execer added in v0.3.0

type Execer interface {
	ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
}

Execer is the part of *sql.DB (and *tenant.DB) tracking needs.

type FTPDriver

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

func NewFTPDriver

func NewFTPDriver(cfg map[string]any) (*FTPDriver, error)

func (*FTPDriver) Delete

func (d *FTPDriver) Delete(_ context.Context, filePath string) error

func (*FTPDriver) Exists

func (d *FTPDriver) Exists(_ context.Context, filePath string) (bool, error)

func (*FTPDriver) Get

func (d *FTPDriver) Get(_ context.Context, filePath string) (io.ReadCloser, error)

func (*FTPDriver) Put

func (d *FTPDriver) Put(_ context.Context, filePath string, reader io.Reader, _ int64) error

type GCSDriver

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

func NewGCSDriver

func NewGCSDriver(cfg map[string]any) (*GCSDriver, error)

func (*GCSDriver) Delete

func (d *GCSDriver) Delete(ctx context.Context, path string) error

func (*GCSDriver) Exists

func (d *GCSDriver) Exists(ctx context.Context, path string) (bool, error)

func (*GCSDriver) Get

func (d *GCSDriver) Get(ctx context.Context, path string) (io.ReadCloser, error)

func (*GCSDriver) Put

func (d *GCSDriver) Put(ctx context.Context, path string, reader io.Reader, _ int64) error

type LocalDriver

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

func NewLocalDriver

func NewLocalDriver(basePath string) *LocalDriver

func (*LocalDriver) Delete

func (d *LocalDriver) Delete(_ context.Context, path string) error

func (*LocalDriver) Exists

func (d *LocalDriver) Exists(_ context.Context, path string) (bool, error)

func (*LocalDriver) Get

func (d *LocalDriver) Get(_ context.Context, path string) (io.ReadCloser, error)

func (*LocalDriver) Put

func (d *LocalDriver) Put(_ context.Context, path string, reader io.Reader, _ int64) error

type S3Driver

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

func NewS3Driver

func NewS3Driver(cfg map[string]any) (*S3Driver, error)

func (*S3Driver) Delete

func (d *S3Driver) Delete(ctx context.Context, path string) error

func (*S3Driver) Exists

func (d *S3Driver) Exists(ctx context.Context, path string) (bool, error)

func (*S3Driver) Get

func (d *S3Driver) Get(ctx context.Context, path string) (io.ReadCloser, error)

func (*S3Driver) Put

func (d *S3Driver) Put(ctx context.Context, path string, reader io.Reader, size int64) error

type SFTPDriver

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

func NewSFTPDriver

func NewSFTPDriver(cfg map[string]any) (*SFTPDriver, error)

func (*SFTPDriver) Delete

func (d *SFTPDriver) Delete(_ context.Context, filePath string) error

func (*SFTPDriver) Exists

func (d *SFTPDriver) Exists(_ context.Context, filePath string) (bool, error)

func (*SFTPDriver) Get

func (d *SFTPDriver) Get(_ context.Context, filePath string) (io.ReadCloser, error)

func (*SFTPDriver) Put

func (d *SFTPDriver) Put(_ context.Context, filePath string, reader io.Reader, _ int64) error

type StorageDriver

type StorageDriver interface {
	Put(ctx context.Context, path string, reader io.Reader, size int64) error
	Get(ctx context.Context, path string) (io.ReadCloser, error)
	Delete(ctx context.Context, path string) error
	Exists(ctx context.Context, path string) (bool, error)
}

StorageDriver is the interface all storage backends implement.

func NewDriver

func NewDriver(driverName string, cfg map[string]any, localBasePath string) (StorageDriver, error)

NewDriver creates a StorageDriver for the given driver name. localBasePath is used only by the "local" driver (STORAGE_PATH/tenant-id).

type Upload added in v0.3.0

type Upload struct {
	Path        string
	Destination string
}

Upload is one recorded file.

func TrackedUploads added in v0.3.0

func TrackedUploads(ctx context.Context, db *sql.DB) ([]Upload, error)

TrackedUploads lists the recorded files (none if nothing was uploaded).

Jump to

Keyboard shortcuts

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