storage

package
v0.0.0-...-4e09bf3 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileInfo

type FileInfo struct {
	// Size represents the size of the file in bytes.
	Size int64

	// LastModified is the timestamp of when the file was last modified.
	LastModified time.Time

	// IsDir indicates whether the path represents a directory.
	IsDir bool

	// ContentType is the MIME type of the file.
	ContentType string
}

FileInfo holds metadata about a file, such as size and last modified time.

type OS

type OS struct {
	BasePath string
}

OS implements the Storage interface for the local file system.

func NewOSStorage

func NewOSStorage(basePath string) *OS

NewOSStorage creates a new OS instance.

func (*OS) Delete

func (s *OS) Delete(_ context.Context, path string) error

func (*OS) Download

func (s *OS) Download(_ context.Context, path string) (io.ReadCloser, error)

func (*OS) Exists

func (s *OS) Exists(_ context.Context, path string) (bool, error)

func (*OS) List

func (s *OS) List(_ context.Context, prefix string) ([]string, error)

func (*OS) Stat

func (s *OS) Stat(_ context.Context, path string) (*FileInfo, error)

func (*OS) Upload

func (s *OS) Upload(_ context.Context, path string, content io.Reader) error

type Provider

type Provider interface {
	// Upload stores the content from the provided io.Reader at the specified path.
	// It returns an error if the upload fails.
	Upload(ctx context.Context, path string, content io.Reader) error

	// Delete removes the file at the specified path. It returns an error if the
	// deletion fails or if the file doesn't exist.
	Delete(ctx context.Context, path string) error

	// List returns a slice of strings representing the names of files and
	// directories under the specified prefix. It returns an error if the listing
	// operation fails.
	List(ctx context.Context, prefix string) ([]string, error)

	// Download retrieves the content of the file at the specified path. It returns
	// an io.ReadCloser for reading the file's content and an error if the download
	// fails. The caller is responsible for closing the returned io.ReadCloser.
	Download(ctx context.Context, path string) (io.ReadCloser, error)

	// Exists checks if a file or directory exists at the specified path. It
	// returns true if the path exists, false if it doesn't, and an error if the
	// check fails.
	Exists(ctx context.Context, path string) (bool, error)

	// Stat retrieves metadata about the file or directory at the specified path.
	// It returns a FileInfo struct containing the metadata and an error if the
	// operation fails.
	Stat(ctx context.Context, path string) (*FileInfo, error)
}

Provider defines the interface for file operations on different backends (e.g., S3, local filesystem).

type S3

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

S3 implements the Storage interface for AWS S3.

func NewS3Storage

func NewS3Storage(ctx context.Context, cfg S3Config) (*S3, error)

NewS3Storage creates a new S3 instance with the provided configuration.

func (*S3) Delete

func (s *S3) Delete(ctx context.Context, path string) error

func (*S3) Download

func (s *S3) Download(ctx context.Context, path string) (io.ReadCloser, error)

func (*S3) Exists

func (s *S3) Exists(ctx context.Context, path string) (bool, error)

func (*S3) List

func (s *S3) List(ctx context.Context, prefix string) ([]string, error)

func (*S3) Stat

func (s *S3) Stat(ctx context.Context, path string) (*FileInfo, error)

func (*S3) Upload

func (s *S3) Upload(ctx context.Context, path string, content io.Reader) error

type S3Config

type S3Config struct {
	Bucket          string
	Region          string
	AccessKeyID     string
	SecretAccessKey string
	Endpoint        string
}

S3Config holds the configuration for S3.

func (*S3Config) Validate

func (cfg *S3Config) Validate() error

Validate validates the S3Config to ensure that all required fields are set.

Directories

Path Synopsis
Package storagefakes is a generated GoMock package.
Package storagefakes is a generated GoMock package.

Jump to

Keyboard shortcuts

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