backend

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListBuckets

func ListBuckets(ctx context.Context, cfg aws.Config, opts S3Options) ([]string, error)

ListBuckets returns all accessible bucket names.

Types

type Backend

type Backend interface {
	// ID returns a stable identifier for this backend instance (e.g. "s3://bucket",
	// "sftp://host", "local:///path"). Two backends with the same ID can use
	// server-side operations; different IDs require cross-backend copy.
	ID() string
	ListDir(path string) ([]FileEntry, error)
	Stat(path string) (FileEntry, error)
	Read(path string) (io.ReadCloser, error)
	Write(path string, r io.Reader) error
	Mkdir(path string) error
	Delete(path string) error
	Rename(oldPath, newPath string) error
	GetMetadata(path string) (FileMetadata, error)
}

Backend is the common abstraction for S3, SFTP, and other storage backends.

func NewFromProfile

func NewFromProfile(profile appconfig.Profile) (Backend, error)

NewFromProfile creates a Backend from the given profile configuration.

type Checksummer

type Checksummer interface {
	Checksum(path string) (string, error)
}

Checksummer is an optional interface for backends that can provide content checksums without downloading the full file (e.g., S3 ETags).

type Copier

type Copier interface {
	Copy(src, dst string) error
}

Copier is an optional interface for backends that support server-side copy.

type FileEntry

type FileEntry struct {
	Name        string
	Path        string
	Size        int64
	IsDir       bool
	Modified    time.Time
	Permissions string // e.g. "drwxr-xr-x" or "-rw-r--r--"
}

FileEntry represents a file or directory in any backend.

type FileMetadata

type FileMetadata struct {
	FileEntry
	StorageClass string
	ETag         string
	ContentType  string
	CustomMeta   map[string]string
	Tags         map[string]string
	Encryption   string
	VersionID    string
}

FileMetadata holds extended file metadata for S3 objects.

type GCSBackend

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

GCSBackend implements Backend for Google Cloud Storage.

func NewGCSBackend

func NewGCSBackend(opts GCSOptions) (*GCSBackend, error)

NewGCSBackend creates a new GCS backend for the given bucket.

func (*GCSBackend) Copy

func (b *GCSBackend) Copy(src, dst string) error

Copy performs a server-side copy within the same bucket.

func (*GCSBackend) Delete

func (b *GCSBackend) Delete(path string) error

func (*GCSBackend) GetMetadata

func (b *GCSBackend) GetMetadata(path string) (FileMetadata, error)

GetMetadata returns extended metadata for a GCS object.

func (*GCSBackend) ID

func (b *GCSBackend) ID() string

func (*GCSBackend) ListDir

func (b *GCSBackend) ListDir(path string) ([]FileEntry, error)

func (*GCSBackend) Mkdir

func (b *GCSBackend) Mkdir(path string) error

func (*GCSBackend) Read

func (b *GCSBackend) Read(path string) (io.ReadCloser, error)

func (*GCSBackend) Rename

func (b *GCSBackend) Rename(oldPath, newPath string) error

func (*GCSBackend) Stat

func (b *GCSBackend) Stat(path string) (FileEntry, error)

func (*GCSBackend) Write

func (b *GCSBackend) Write(path string, r io.Reader) error

type GCSOptions

type GCSOptions struct {
	Bucket          string
	ProjectID       string
	CredentialsFile string
	UseADC          bool   // default true — use Application Default Credentials
	Endpoint        string // optional custom/emulator endpoint
}

GCSOptions holds configuration for Google Cloud Storage clients.

type LocalBackend

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

LocalBackend implements Backend for the local filesystem.

func NewLocalBackend

func NewLocalBackend(root string) *LocalBackend

NewLocalBackend creates a local filesystem backend rooted at the given directory.

func (*LocalBackend) Delete

func (b *LocalBackend) Delete(path string) error

func (*LocalBackend) GetMetadata

func (b *LocalBackend) GetMetadata(path string) (FileMetadata, error)

func (*LocalBackend) ID

func (b *LocalBackend) ID() string

func (*LocalBackend) ListDir

func (b *LocalBackend) ListDir(path string) ([]FileEntry, error)

func (*LocalBackend) Mkdir

func (b *LocalBackend) Mkdir(path string) error

func (*LocalBackend) Read

func (b *LocalBackend) Read(path string) (io.ReadCloser, error)

func (*LocalBackend) Rename

func (b *LocalBackend) Rename(oldPath, newPath string) error

func (*LocalBackend) SetModTime

func (b *LocalBackend) SetModTime(path string, modTime time.Time) error

SetModTime updates file timestamps for sync exact-timestamp semantics.

func (*LocalBackend) Stat

func (b *LocalBackend) Stat(path string) (FileEntry, error)

func (*LocalBackend) Write

func (b *LocalBackend) Write(path string, r io.Reader) error

type ModTimeSetter

type ModTimeSetter interface {
	SetModTime(path string, modTime time.Time) error
}

ModTimeSetter is an optional interface for destinations that can preserve source modification timestamps after writes.

type MultiBucketBackend

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

MultiBucketBackend presents all buckets as top-level directories. Paths are formatted as "bucket-name/key".

func NewMultiBucketBackend

func NewMultiBucketBackend(cfg aws.Config, buckets []string, opts S3Options) *MultiBucketBackend

NewMultiBucketBackend creates a backend that spans all given buckets.

func (*MultiBucketBackend) Delete

func (m *MultiBucketBackend) Delete(path string) error

func (*MultiBucketBackend) GetMetadata

func (m *MultiBucketBackend) GetMetadata(path string) (FileMetadata, error)

func (*MultiBucketBackend) ID

func (b *MultiBucketBackend) ID() string

func (*MultiBucketBackend) ListDir

func (m *MultiBucketBackend) ListDir(path string) ([]FileEntry, error)

func (*MultiBucketBackend) Mkdir

func (m *MultiBucketBackend) Mkdir(path string) error

func (*MultiBucketBackend) Read

func (m *MultiBucketBackend) Read(path string) (io.ReadCloser, error)

func (*MultiBucketBackend) Rename

func (m *MultiBucketBackend) Rename(oldPath, newPath string) error

func (*MultiBucketBackend) Stat

func (m *MultiBucketBackend) Stat(path string) (FileEntry, error)

func (*MultiBucketBackend) Write

func (m *MultiBucketBackend) Write(path string, r io.Reader) error

type S3Backend

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

S3Backend implements Backend for Amazon S3.

func NewS3Backend

func NewS3Backend(cfg aws.Config, bucket string, opts S3Options) *S3Backend

NewS3Backend creates a new S3 backend for the given bucket.

func (*S3Backend) Copy

func (b *S3Backend) Copy(src, dst string) error

Copy performs a server-side copy within the same bucket.

func (*S3Backend) Delete

func (b *S3Backend) Delete(path string) error

func (*S3Backend) GetMetadata

func (b *S3Backend) GetMetadata(path string) (FileMetadata, error)

GetMetadata returns extended metadata for an S3 object.

func (*S3Backend) ID

func (b *S3Backend) ID() string

func (*S3Backend) ListDir

func (b *S3Backend) ListDir(path string) ([]FileEntry, error)

func (*S3Backend) Mkdir

func (b *S3Backend) Mkdir(path string) error

func (*S3Backend) Read

func (b *S3Backend) Read(path string) (io.ReadCloser, error)

func (*S3Backend) Rename

func (b *S3Backend) Rename(oldPath, newPath string) error

func (*S3Backend) Stat

func (b *S3Backend) Stat(path string) (FileEntry, error)

func (*S3Backend) Write

func (b *S3Backend) Write(path string, r io.Reader) error

func (*S3Backend) WriteWithSize

func (b *S3Backend) WriteWithSize(path string, r io.Reader, size int64) error

type S3Options

type S3Options struct {
	Endpoint string
}

S3Options holds optional configuration for S3 clients.

type SFTPBackend

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

SFTPBackend implements Backend for SFTP remote filesystems.

func NewSFTPBackend

func NewSFTPBackend(opts SFTPOptions) (*SFTPBackend, error)

NewSFTPBackend establishes an SSH connection and returns an SFTPBackend.

func (*SFTPBackend) Close

func (b *SFTPBackend) Close() error

Close shuts down the SFTP client and underlying SSH connection.

func (*SFTPBackend) Delete

func (b *SFTPBackend) Delete(filePath string) error

Delete removes a file or directory (recursively for directories).

func (*SFTPBackend) GetMetadata

func (b *SFTPBackend) GetMetadata(path string) (FileMetadata, error)

GetMetadata returns metadata for an SFTP file.

func (*SFTPBackend) HomeDir

func (b *SFTPBackend) HomeDir() string

HomeDir returns the absolute path of the remote user's home directory.

func (*SFTPBackend) ID

func (b *SFTPBackend) ID() string

func (*SFTPBackend) ListDir

func (b *SFTPBackend) ListDir(dirPath string) ([]FileEntry, error)

ListDir returns the contents of a remote directory.

func (*SFTPBackend) Mkdir

func (b *SFTPBackend) Mkdir(dirPath string) error

Mkdir creates a remote directory and any necessary parents.

func (*SFTPBackend) Read

func (b *SFTPBackend) Read(filePath string) (io.ReadCloser, error)

Read opens a remote file for reading.

func (*SFTPBackend) Rename

func (b *SFTPBackend) Rename(oldPath, newPath string) error

Rename moves or renames a remote file or directory.

func (*SFTPBackend) SetModTime

func (b *SFTPBackend) SetModTime(filePath string, modTime time.Time) error

SetModTime preserves source modification timestamps on SFTP destinations.

func (*SFTPBackend) Stat

func (b *SFTPBackend) Stat(filePath string) (FileEntry, error)

Stat returns metadata for a single remote path.

func (*SFTPBackend) Write

func (b *SFTPBackend) Write(filePath string, r io.Reader) error

Write creates or overwrites a remote file, creating parent directories as needed.

type SFTPOptions

type SFTPOptions struct {
	Host                  string
	Port                  int
	Username              string
	Password              string
	PrivateKeyPath        string
	PrivateKeyPassphrase  string
	KnownHostsPath        string
	InsecureIgnoreHostKey bool
}

SFTPOptions holds the configuration for an SFTP connection.

type SizedWriter

type SizedWriter interface {
	WriteWithSize(path string, r io.Reader, size int64) error
}

SizedWriter is an optional interface backends can implement to accept a content-length hint alongside the data stream (required by S3 PutObject).

Jump to

Keyboard shortcuts

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