Documentation ¶
Index ¶
- Constants
- type FS
- type File
- type GCSStorage
- func (gcs *GCSStorage) Copy(sourcePath, destPath string) error
- func (gcs *GCSStorage) CreateDirectory(path string) error
- func (gcs *GCSStorage) Delete(path string) error
- func (gcs *GCSStorage) Driver() string
- func (gcs *GCSStorage) Exists(path string) (bool, error)
- func (gcs *GCSStorage) GetUrl(path string) (string, error)
- func (gcs *GCSStorage) Open(path string) (*os.File, error)
- func (gcs *GCSStorage) Read(path string) (io.ReadCloser, error)
- func (gcs *GCSStorage) Rename(oldPath, newPath string) error
- func (gcs *GCSStorage) Upload(file multipart.File, header *multipart.FileHeader, dir string) (*os.File, error)
- func (gcs *GCSStorage) Write(path string, contents []byte) error
- type LocalStorage
- func (ls *LocalStorage) Copy(sourcePath, destinationPath string) error
- func (ls *LocalStorage) CreateDirectory(path string) error
- func (ls *LocalStorage) Delete(path string) error
- func (ls *LocalStorage) Driver() string
- func (ls *LocalStorage) Exists(path string) (bool, error)
- func (ls *LocalStorage) GetUrl(path string) (string, error)
- func (ls *LocalStorage) Open(path string) (*os.File, error)
- func (ls *LocalStorage) Read(path string) (io.ReadCloser, error)
- func (ls *LocalStorage) Rename(oldPath, newPath string) error
- func (ls *LocalStorage) Upload(file multipart.File, header *multipart.FileHeader, dir string) (*os.File, error)
- func (ls *LocalStorage) Write(path string, contents []byte) error
- type MemoryStorage
- func (fs *MemoryStorage) Copy(sourcePath, destinationPath string) error
- func (fs *MemoryStorage) CreateDirectory(path string) error
- func (fs *MemoryStorage) Delete(path string) error
- func (fs *MemoryStorage) Driver() string
- func (fs *MemoryStorage) Exists(path string) (bool, error)
- func (fs *MemoryStorage) GetUrl(path string) (string, error)
- func (fs *MemoryStorage) Open(path string) (*os.File, error)
- func (fs *MemoryStorage) Read(path string) (io.ReadCloser, error)
- func (fs *MemoryStorage) Rename(oldPath, newPath string) error
- func (fs *MemoryStorage) Upload(file multipart.File, header *multipart.FileHeader, dir string) (*os.File, error)
- func (fs *MemoryStorage) Write(path string, contents []byte) error
- type S3Storage
- func (s3s *S3Storage) Copy(sourcePath, destPath string) error
- func (s3s *S3Storage) CreateDirectory(path string) error
- func (s3s *S3Storage) Delete(path string) error
- func (s3s *S3Storage) Driver() string
- func (s3s *S3Storage) Exists(path string) (bool, error)
- func (s3s *S3Storage) GetUrl(path string) (string, error)
- func (s3s *S3Storage) Open(path string) (*os.File, error)
- func (s3s *S3Storage) Read(path string) (io.ReadCloser, error)
- func (s3s *S3Storage) Rename(oldPath, newPath string) error
- func (s3s *S3Storage) Upload(file multipart.File, header *multipart.FileHeader, dir string) (*os.File, error)
- func (s3s *S3Storage) Write(path string, contents []byte) error
Constants ¶
const ( DRIVER_MEMORY = "memory" DRIVER_LOCAL = "local" DRIVER_GCS = "gcs" DRIVER_S3 = "s3" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FS ¶
type FS interface { // Driver returns the name of the current driver Driver() string // Read a file from storage. Read(path string) (io.ReadCloser, error) // Write a file to storage. Write(path string, contents []byte) error // Delete a file from storage. Delete(path string) error // Exists checks if a file exists in storage. Exists(path string) (bool, error) // Rename a file in storage. Rename(oldPath, newPath string) error // Copy a file in storage. Copy(sourcePath, destinationPath string) error // CreateDirectory creates a new directory if doesn't already exist for the given path CreateDirectory(path string) error // GetUrl gets the URL for a file in storage (optional). // This method may not be applicable to all storage systems. // For example, local storage may return a file path, while cloud storage may return a URL. GetUrl(path string) (string, error) // Open opens a file Open(path string) (*os.File, error) // Upload uploads a file to the implemented driver Upload(file multipart.File, header *multipart.FileHeader, dir string) (*os.File, error) }
FS defines the methods that any storage system must implement.
type GCSStorage ¶
type GCSStorage struct { // GCS bucket name BucketName string // GCS client Client *storage.Client }
GCSStorage is an implementation of StorageInterface for Google Cloud Storage.
func NewGCSStorage ¶
func NewGCSStorage(projectID, bucket, serviceAccountKey string) (*GCSStorage, error)
func (*GCSStorage) Copy ¶
func (gcs *GCSStorage) Copy(sourcePath, destPath string) error
func (*GCSStorage) CreateDirectory ¶
func (gcs *GCSStorage) CreateDirectory(path string) error
func (*GCSStorage) Delete ¶
func (gcs *GCSStorage) Delete(path string) error
func (*GCSStorage) Driver ¶
func (gcs *GCSStorage) Driver() string
func (*GCSStorage) Read ¶
func (gcs *GCSStorage) Read(path string) (io.ReadCloser, error)
func (*GCSStorage) Rename ¶
func (gcs *GCSStorage) Rename(oldPath, newPath string) error
type LocalStorage ¶
type LocalStorage struct { // Root directory of the storage. RootDirectory string }
LocalStorage is an implementation of StorageInterface for local file system.
func NewLocalStorage ¶
func NewLocalStorage(basePath string) *LocalStorage
func (*LocalStorage) Copy ¶
func (ls *LocalStorage) Copy(sourcePath, destinationPath string) error
func (*LocalStorage) CreateDirectory ¶
func (ls *LocalStorage) CreateDirectory(path string) error
func (*LocalStorage) Delete ¶
func (ls *LocalStorage) Delete(path string) error
func (*LocalStorage) Driver ¶
func (ls *LocalStorage) Driver() string
func (*LocalStorage) Read ¶
func (ls *LocalStorage) Read(path string) (io.ReadCloser, error)
func (*LocalStorage) Rename ¶
func (ls *LocalStorage) Rename(oldPath, newPath string) error
type MemoryStorage ¶
type MemoryStorage struct {
// contains filtered or unexported fields
}
MemoryStorage is an in-memory implementation of the FS interface.
func NewMemoryStorage ¶
func NewMemoryStorage() *MemoryStorage
NewMemoryStorage returns a new MemoryStorage instance.
func (*MemoryStorage) Copy ¶
func (fs *MemoryStorage) Copy(sourcePath, destinationPath string) error
Copy copies a file in memory.
func (*MemoryStorage) CreateDirectory ¶
func (fs *MemoryStorage) CreateDirectory(path string) error
CreateDirectory is a no-op for memory storage but can simulate directory creation.
func (*MemoryStorage) Delete ¶
func (fs *MemoryStorage) Delete(path string) error
Delete deletes a file from memory.
func (*MemoryStorage) Driver ¶
func (fs *MemoryStorage) Driver() string
Driver returns the name of the current driver.
func (*MemoryStorage) Exists ¶
func (fs *MemoryStorage) Exists(path string) (bool, error)
Exists checks if a file exists in memory.
func (*MemoryStorage) GetUrl ¶
func (fs *MemoryStorage) GetUrl(path string) (string, error)
GetUrl returns a mock URL for memory-stored files.
func (*MemoryStorage) Open ¶
func (fs *MemoryStorage) Open(path string) (*os.File, error)
Open opens a file (not fully applicable for memory but returns a mock).
func (*MemoryStorage) Read ¶
func (fs *MemoryStorage) Read(path string) (io.ReadCloser, error)
Read reads a file from memory.
func (*MemoryStorage) Rename ¶
func (fs *MemoryStorage) Rename(oldPath, newPath string) error
Rename renames a file in memory.
type S3Storage ¶
type S3Storage struct { // S3 bucket name BucketName string // AWS session Session *session.Session // AWS S3 client S3Client *s3.S3 }
S3Storage is an implementation of StorageInterface for Amazon S3.
func NewS3Storage ¶
func (*S3Storage) Copy ¶
Copy copies the file from the source path to the destination path in S3 storage.