Documentation
¶
Overview ¶
Package oss provides a unified object storage abstraction layer supporting multiple cloud storage providers including AWS S3, Azure Blob, Aliyun OSS, Tencent COS, Google Cloud Storage, MinIO, Qiniu Kodo, Synology NAS, and local filesystem.
All providers implement a common Interface for consistent operations across different storage backends. Drivers are auto-registered via init() functions, enabling transparent provider selection at runtime.
Index ¶
- func RegisterDriver(driver Driver)
- type AliyunAdapter
- func (a *AliyunAdapter) Delete(path string) error
- func (a *AliyunAdapter) Exists(path string) (bool, error)
- func (a *AliyunAdapter) Get(path string) (*os.File, error)
- func (a *AliyunAdapter) GetEndpoint() string
- func (a *AliyunAdapter) GetStream(path string) (io.ReadCloser, error)
- func (a *AliyunAdapter) GetURL(path string) (string, error)
- func (a *AliyunAdapter) List(path string) ([]*Object, error)
- func (a *AliyunAdapter) Put(path string, reader io.Reader) (*Object, error)
- func (a *AliyunAdapter) Stat(path string) (*Object, error)
- type AzureAdapter
- func (a *AzureAdapter) Delete(path string) error
- func (a *AzureAdapter) Exists(path string) (bool, error)
- func (a *AzureAdapter) Get(path string) (*os.File, error)
- func (a *AzureAdapter) GetEndpoint() string
- func (a *AzureAdapter) GetStream(path string) (io.ReadCloser, error)
- func (a *AzureAdapter) GetURL(path string) (string, error)
- func (a *AzureAdapter) List(path string) ([]*Object, error)
- func (a *AzureAdapter) Put(path string, reader io.Reader) (*Object, error)
- func (a *AzureAdapter) Stat(path string) (*Object, error)
- type Config
- type Driver
- type FileSystem
- type GCSAdapter
- func (a *GCSAdapter) Delete(path string) error
- func (a *GCSAdapter) Exists(path string) (bool, error)
- func (a *GCSAdapter) Get(path string) (*os.File, error)
- func (a *GCSAdapter) GetEndpoint() string
- func (a *GCSAdapter) GetStream(path string) (io.ReadCloser, error)
- func (a *GCSAdapter) GetURL(path string) (string, error)
- func (a *GCSAdapter) List(path string) ([]*Object, error)
- func (a *GCSAdapter) Put(path string, reader io.Reader) (*Object, error)
- func (a *GCSAdapter) Stat(path string) (*Object, error)
- type Interface
- type LocalFileSystem
- func (fs *LocalFileSystem) Delete(p string) error
- func (fs *LocalFileSystem) Exists(p string) (bool, error)
- func (fs *LocalFileSystem) Get(p string) (*os.File, error)
- func (fs *LocalFileSystem) GetEndpoint() string
- func (fs *LocalFileSystem) GetFullPath(p string) string
- func (fs *LocalFileSystem) GetStream(p string) (io.ReadCloser, error)
- func (fs *LocalFileSystem) GetURL(p string) (string, error)
- func (fs *LocalFileSystem) List(p string) ([]*Object, error)
- func (fs *LocalFileSystem) Put(p string, r io.Reader) (*Object, error)
- func (fs *LocalFileSystem) Stat(p string) (*Object, error)
- type MinioAdapter
- func (a *MinioAdapter) Delete(path string) error
- func (a *MinioAdapter) Exists(path string) (bool, error)
- func (a *MinioAdapter) Get(path string) (*os.File, error)
- func (a *MinioAdapter) GetEndpoint() string
- func (a *MinioAdapter) GetStream(path string) (io.ReadCloser, error)
- func (a *MinioAdapter) GetURL(path string) (string, error)
- func (a *MinioAdapter) List(path string) ([]*Object, error)
- func (a *MinioAdapter) Put(path string, reader io.Reader) (*Object, error)
- func (a *MinioAdapter) Stat(path string) (*Object, error)
- type Object
- type QiniuAdapter
- func (a *QiniuAdapter) Delete(path string) error
- func (a *QiniuAdapter) Exists(path string) (bool, error)
- func (a *QiniuAdapter) Get(path string) (*os.File, error)
- func (a *QiniuAdapter) GetEndpoint() string
- func (a *QiniuAdapter) GetStream(path string) (io.ReadCloser, error)
- func (a *QiniuAdapter) GetURL(path string) (string, error)
- func (a *QiniuAdapter) List(path string) ([]*Object, error)
- func (a *QiniuAdapter) Put(path string, reader io.Reader) (*Object, error)
- func (a *QiniuAdapter) Stat(path string) (*Object, error)
- type S3Adapter
- func (a *S3Adapter) Delete(path string) error
- func (a *S3Adapter) Exists(path string) (bool, error)
- func (a *S3Adapter) Get(path string) (*os.File, error)
- func (a *S3Adapter) GetEndpoint() string
- func (a *S3Adapter) GetStream(path string) (io.ReadCloser, error)
- func (a *S3Adapter) GetURL(path string) (string, error)
- func (a *S3Adapter) List(path string) ([]*Object, error)
- func (a *S3Adapter) Put(path string, reader io.Reader) (*Object, error)
- func (a *S3Adapter) Stat(path string) (*Object, error)
- type SynologyAdapter
- func (a *SynologyAdapter) Delete(path string) error
- func (a *SynologyAdapter) Exists(path string) (bool, error)
- func (a *SynologyAdapter) Get(path string) (*os.File, error)
- func (a *SynologyAdapter) GetEndpoint() string
- func (a *SynologyAdapter) GetStream(path string) (io.ReadCloser, error)
- func (a *SynologyAdapter) GetURL(path string) (string, error)
- func (a *SynologyAdapter) List(path string) ([]*Object, error)
- func (a *SynologyAdapter) Put(path string, reader io.Reader) (*Object, error)
- func (a *SynologyAdapter) Stat(path string) (*Object, error)
- type TencentAdapter
- func (a *TencentAdapter) Delete(path string) error
- func (a *TencentAdapter) Exists(path string) (bool, error)
- func (a *TencentAdapter) Get(path string) (*os.File, error)
- func (a *TencentAdapter) GetEndpoint() string
- func (a *TencentAdapter) GetStream(path string) (io.ReadCloser, error)
- func (a *TencentAdapter) GetURL(path string) (string, error)
- func (a *TencentAdapter) List(path string) ([]*Object, error)
- func (a *TencentAdapter) Put(path string, reader io.Reader) (*Object, error)
- func (a *TencentAdapter) Stat(path string) (*Object, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterDriver ¶
func RegisterDriver(driver Driver)
RegisterDriver registers a storage driver. Typically called in the driver package's init function.
Types ¶
type AliyunAdapter ¶
type AliyunAdapter struct {
// contains filtered or unexported fields
}
AliyunAdapter implements the Interface for Aliyun OSS storage.
func NewAliyunAdapter ¶
func NewAliyunAdapter(accessKeyID, secretAccessKey, region, bucket, endpoint string) (*AliyunAdapter, error)
NewAliyunAdapter creates a new Aliyun OSS storage adapter.
func (*AliyunAdapter) Delete ¶
func (a *AliyunAdapter) Delete(path string) error
Delete removes an object from the Aliyun OSS bucket.
func (*AliyunAdapter) Exists ¶ added in v0.2.3
func (a *AliyunAdapter) Exists(path string) (bool, error)
Exists checks if an object exists in the Aliyun OSS bucket.
func (*AliyunAdapter) Get ¶
func (a *AliyunAdapter) Get(path string) (*os.File, error)
Get downloads a file from Aliyun OSS to a temporary local file.
func (*AliyunAdapter) GetEndpoint ¶
func (a *AliyunAdapter) GetEndpoint() string
GetEndpoint returns the Aliyun OSS endpoint URL.
func (*AliyunAdapter) GetStream ¶
func (a *AliyunAdapter) GetStream(path string) (io.ReadCloser, error)
GetStream returns a readable stream for the Aliyun OSS object.
func (*AliyunAdapter) GetURL ¶
func (a *AliyunAdapter) GetURL(path string) (string, error)
GetURL generates a presigned URL valid for 1 hour.
func (*AliyunAdapter) List ¶
func (a *AliyunAdapter) List(path string) ([]*Object, error)
List returns all objects under the specified prefix.
type AzureAdapter ¶
type AzureAdapter struct {
// contains filtered or unexported fields
}
AzureAdapter implements the Interface for Azure Blob Storage.
func NewAzureAdapter ¶
func NewAzureAdapter(accountName, accountKey, containerName string) (*AzureAdapter, error)
NewAzureAdapter creates a new Azure Blob Storage adapter.
func (*AzureAdapter) Delete ¶
func (a *AzureAdapter) Delete(path string) error
Delete removes a blob from the Azure container.
func (*AzureAdapter) Exists ¶ added in v0.2.3
func (a *AzureAdapter) Exists(path string) (bool, error)
Exists checks if a blob exists in the Azure container.
func (*AzureAdapter) Get ¶
func (a *AzureAdapter) Get(path string) (*os.File, error)
Get downloads a blob from Azure to a temporary local file.
func (*AzureAdapter) GetEndpoint ¶
func (a *AzureAdapter) GetEndpoint() string
GetEndpoint returns the Azure Blob Storage endpoint URL.
func (*AzureAdapter) GetStream ¶
func (a *AzureAdapter) GetStream(path string) (io.ReadCloser, error)
GetStream returns a readable stream for the Azure blob.
func (*AzureAdapter) GetURL ¶
func (a *AzureAdapter) GetURL(path string) (string, error)
GetURL generates a SAS URL valid for 1 hour.
func (*AzureAdapter) List ¶
func (a *AzureAdapter) List(path string) ([]*Object, error)
List returns all blobs under the specified prefix.
type Config ¶
type Config struct {
Provider string `json:"provider" yaml:"provider"` // Storage provider: minio, s3, aliyun, azure, tencent, qiniu, gcs, synology, filesystem
ID string `json:"id" yaml:"id"` // Access key ID / Account name
Secret string `json:"secret" yaml:"secret"` // Secret access key / Account key
Region string `json:"region" yaml:"region"` // Region (required for cloud storage)
Bucket string `json:"bucket" yaml:"bucket"` // Bucket name / Container name / Local path
Endpoint string `json:"endpoint" yaml:"endpoint"` // Custom endpoint (required for MinIO, Synology)
ServiceAccountJSON string `json:"service_account_json,omitempty" yaml:"service_account_json,omitempty"` // Service account JSON file path for Google Cloud Storage
OtpCode string `json:"otp_code,omitempty" yaml:"otp_code,omitempty"` // Synology 2FA code (optional)
Debug bool `json:"debug,omitempty" yaml:"debug,omitempty"` // Enable debug mode (optional)
AppID string `json:"app_id,omitempty" yaml:"app_id,omitempty"` // Tencent COS Application ID
}
Config holds configuration for object storage providers.
type Driver ¶
type Driver interface {
// Name returns the driver name.
Name() string
// Connect establishes a connection to the storage service.
Connect(ctx context.Context, cfg *Config) (Interface, error)
// Close closes the storage connection.
Close(conn Interface) error
}
Driver defines the storage driver interface. Implement this interface to add support for new storage providers.
type FileSystem ¶
type FileSystem interface {
GetFullPath(p string) string
Get(p string) (*os.File, error)
GetStream(p string) (io.ReadCloser, error)
Put(p string, r io.Reader) (*Object, error)
Delete(p string) error
List(p string) ([]*Object, error)
GetEndpoint() string
GetURL(p string) (string, error)
}
FileSystem represents the interface for file system storage
type GCSAdapter ¶
type GCSAdapter struct {
// contains filtered or unexported fields
}
GCSAdapter implements the Interface for Google Cloud Storage.
func NewGCSAdapter ¶
func NewGCSAdapter(serviceAccountJSON, bucket string) (*GCSAdapter, error)
NewGCSAdapter creates a new Google Cloud Storage adapter.
func (*GCSAdapter) Delete ¶
func (a *GCSAdapter) Delete(path string) error
Delete removes an object from the GCS bucket.
func (*GCSAdapter) Exists ¶ added in v0.2.3
func (a *GCSAdapter) Exists(path string) (bool, error)
Exists checks if an object exists in the GCS bucket.
func (*GCSAdapter) Get ¶
func (a *GCSAdapter) Get(path string) (*os.File, error)
Get downloads an object from GCS to a temporary local file.
func (*GCSAdapter) GetEndpoint ¶
func (a *GCSAdapter) GetEndpoint() string
GetEndpoint returns the Google Cloud Storage endpoint URL.
func (*GCSAdapter) GetStream ¶
func (a *GCSAdapter) GetStream(path string) (io.ReadCloser, error)
GetStream returns a readable stream for the GCS object.
func (*GCSAdapter) GetURL ¶
func (a *GCSAdapter) GetURL(path string) (string, error)
GetURL generates a signed URL valid for 1 hour.
func (*GCSAdapter) List ¶
func (a *GCSAdapter) List(path string) ([]*Object, error)
List returns all objects under the specified prefix.
type Interface ¶
type Interface interface {
// Get downloads a file to a temporary file and returns the file handle.
// Caller is responsible for closing the file and removing it when done.
Get(path string) (*os.File, error)
// GetStream returns a readable stream for streaming large file downloads.
// Caller is responsible for closing the reader when done.
GetStream(path string) (io.ReadCloser, error)
// Put uploads a file from the given reader to the specified path.
// Returns object metadata on success.
Put(path string, reader io.Reader) (*Object, error)
// Delete removes the file at the specified path.
// Returns nil if file doesn't exist or was successfully deleted.
Delete(path string) error
// List returns all objects under the specified path prefix.
// Returns empty slice if no objects found.
List(path string) ([]*Object, error)
// GetURL generates a presigned URL for downloading the file.
// URL is typically valid for 1 hour.
GetURL(path string) (string, error)
// GetEndpoint returns the storage service endpoint URL.
GetEndpoint() string
// Exists checks if an object exists at the specified path.
Exists(path string) (bool, error)
// Stat retrieves object metadata without downloading content.
Stat(path string) (*Object, error)
}
Interface defines unified object storage operations. All storage providers implement this interface for consistent API access.
func NewStorage ¶
NewStorage creates a storage instance based on the provided configuration. Automatically selects the appropriate storage provider.
type LocalFileSystem ¶
type LocalFileSystem struct {
Folder string
}
LocalFileSystem implements the FileSystem interface for local file system storage
func NewFileSystem ¶
func NewFileSystem(folder string) *LocalFileSystem
NewFileSystem creates a new local file system storage
func (*LocalFileSystem) Delete ¶
func (fs *LocalFileSystem) Delete(p string) error
Delete deletes a file
func (*LocalFileSystem) Exists ¶ added in v0.2.3
func (fs *LocalFileSystem) Exists(p string) (bool, error)
Exists checks if a file exists at the specified path.
func (*LocalFileSystem) Get ¶
func (fs *LocalFileSystem) Get(p string) (*os.File, error)
Get receives a file with the given path
func (*LocalFileSystem) GetEndpoint ¶
func (fs *LocalFileSystem) GetEndpoint() string
GetEndpoint gets the endpoint (for FileSystem, it's just the base path)
func (*LocalFileSystem) GetFullPath ¶
func (fs *LocalFileSystem) GetFullPath(p string) string
GetFullPath returns the full path from absolute/relative path
func (*LocalFileSystem) GetStream ¶
func (fs *LocalFileSystem) GetStream(p string) (io.ReadCloser, error)
GetStream gets a file as a stream
func (*LocalFileSystem) GetURL ¶
func (fs *LocalFileSystem) GetURL(p string) (string, error)
GetURL returns the public accessible URL. For local filesystem, returns the relative path.
func (*LocalFileSystem) List ¶
func (fs *LocalFileSystem) List(p string) ([]*Object, error)
List lists files
type MinioAdapter ¶
type MinioAdapter struct {
// contains filtered or unexported fields
}
MinioAdapter implements the Interface for MinIO object storage. Compatible with any S3-compatible storage service.
func NewMinioAdapter ¶
func NewMinioAdapter(endpoint, accessKeyID, secretAccessKey, bucket string, useSSL bool) (*MinioAdapter, error)
NewMinioAdapter creates a new MinIO storage adapter.
func (*MinioAdapter) Delete ¶
func (a *MinioAdapter) Delete(path string) error
Delete removes an object from the MinIO bucket.
func (*MinioAdapter) Exists ¶ added in v0.2.3
func (a *MinioAdapter) Exists(path string) (bool, error)
Exists checks if an object exists in the MinIO bucket.
func (*MinioAdapter) Get ¶
func (a *MinioAdapter) Get(path string) (*os.File, error)
Get downloads a file from MinIO to a temporary local file.
func (*MinioAdapter) GetEndpoint ¶
func (a *MinioAdapter) GetEndpoint() string
GetEndpoint returns the MinIO endpoint URL.
func (*MinioAdapter) GetStream ¶
func (a *MinioAdapter) GetStream(path string) (io.ReadCloser, error)
GetStream returns a readable stream for the MinIO object.
func (*MinioAdapter) GetURL ¶
func (a *MinioAdapter) GetURL(path string) (string, error)
GetURL generates a presigned URL valid for 1 hour.
func (*MinioAdapter) List ¶
func (a *MinioAdapter) List(path string) ([]*Object, error)
List returns all objects under the specified prefix.
type Object ¶
type Object struct {
Path string // File path in storage
Name string // File name
LastModified *time.Time // Last modification time
Size int64 // File size in bytes
StorageInterface Interface // Associated storage interface
}
Object represents metadata about a stored object.
type QiniuAdapter ¶
type QiniuAdapter struct {
// contains filtered or unexported fields
}
QiniuAdapter implements the Interface for Qiniu Kodo storage.
func NewQiniuAdapter ¶
func NewQiniuAdapter(accessKey, secretKey, bucket, region, domain string) (*QiniuAdapter, error)
NewQiniuAdapter creates a new Qiniu Kodo storage adapter.
func (*QiniuAdapter) Delete ¶
func (a *QiniuAdapter) Delete(path string) error
Delete removes an object from the Qiniu bucket.
func (*QiniuAdapter) Exists ¶ added in v0.2.3
func (a *QiniuAdapter) Exists(path string) (bool, error)
Exists checks if an object exists in the Qiniu bucket.
func (*QiniuAdapter) Get ¶
func (a *QiniuAdapter) Get(path string) (*os.File, error)
Get downloads a file from Qiniu to a temporary local file.
func (*QiniuAdapter) GetEndpoint ¶
func (a *QiniuAdapter) GetEndpoint() string
GetEndpoint returns the Qiniu Kodo endpoint URL.
func (*QiniuAdapter) GetStream ¶
func (a *QiniuAdapter) GetStream(path string) (io.ReadCloser, error)
GetStream returns a readable stream for the Qiniu object.
func (*QiniuAdapter) GetURL ¶
func (a *QiniuAdapter) GetURL(path string) (string, error)
GetURL generates a private signed URL valid for 1 hour.
func (*QiniuAdapter) List ¶
func (a *QiniuAdapter) List(path string) ([]*Object, error)
List returns all objects under the specified prefix.
type S3Adapter ¶
type S3Adapter struct {
// contains filtered or unexported fields
}
S3Adapter implements the Interface for AWS S3 storage. Supports both AWS S3 and S3-compatible services with custom endpoints.
func NewS3Adapter ¶
func NewS3Adapter(accessKeyID, secretAccessKey, region, bucket, endpoint string) (*S3Adapter, error)
NewS3Adapter creates a new S3 storage adapter. For S3-compatible services, set the endpoint parameter.
func (*S3Adapter) GetEndpoint ¶
GetEndpoint returns the S3 endpoint URL.
func (*S3Adapter) GetStream ¶
func (a *S3Adapter) GetStream(path string) (io.ReadCloser, error)
GetStream returns a readable stream for the S3 object.
type SynologyAdapter ¶
type SynologyAdapter struct {
// contains filtered or unexported fields
}
SynologyAdapter implements the Interface for Synology NAS S3-compatible storage.
func NewSynologyAdapter ¶
func NewSynologyAdapter(endpoint, accessKey, secretKey, bucket string, useSSL bool) (*SynologyAdapter, error)
NewSynologyAdapter creates a new Synology NAS storage adapter.
func (*SynologyAdapter) Delete ¶
func (a *SynologyAdapter) Delete(path string) error
Delete removes an object from the Synology bucket.
func (*SynologyAdapter) Exists ¶ added in v0.2.3
func (a *SynologyAdapter) Exists(path string) (bool, error)
Exists checks if an object exists in the Synology bucket.
func (*SynologyAdapter) Get ¶
func (a *SynologyAdapter) Get(path string) (*os.File, error)
Get downloads a file from Synology to a temporary local file.
func (*SynologyAdapter) GetEndpoint ¶
func (a *SynologyAdapter) GetEndpoint() string
GetEndpoint returns the Synology NAS endpoint URL.
func (*SynologyAdapter) GetStream ¶
func (a *SynologyAdapter) GetStream(path string) (io.ReadCloser, error)
GetStream returns a readable stream for the Synology object.
func (*SynologyAdapter) GetURL ¶
func (a *SynologyAdapter) GetURL(path string) (string, error)
GetURL generates a presigned URL valid for 1 hour.
func (*SynologyAdapter) List ¶
func (a *SynologyAdapter) List(path string) ([]*Object, error)
List returns all objects under the specified prefix.
type TencentAdapter ¶
type TencentAdapter struct {
// contains filtered or unexported fields
}
TencentAdapter implements the Interface for Tencent Cloud Object Storage (COS).
func NewTencentAdapter ¶
func NewTencentAdapter(secretID, secretKey, region, bucket, appID string) (*TencentAdapter, error)
NewTencentAdapter creates a new Tencent COS storage adapter.
func (*TencentAdapter) Delete ¶
func (a *TencentAdapter) Delete(path string) error
Delete removes an object from the Tencent COS bucket.
func (*TencentAdapter) Exists ¶ added in v0.2.3
func (a *TencentAdapter) Exists(path string) (bool, error)
Exists checks if an object exists in the Tencent COS bucket.
func (*TencentAdapter) Get ¶
func (a *TencentAdapter) Get(path string) (*os.File, error)
Get downloads a file from Tencent COS to a temporary local file.
func (*TencentAdapter) GetEndpoint ¶
func (a *TencentAdapter) GetEndpoint() string
GetEndpoint returns the Tencent COS endpoint URL.
func (*TencentAdapter) GetStream ¶
func (a *TencentAdapter) GetStream(path string) (io.ReadCloser, error)
GetStream returns a readable stream for the Tencent COS object.
func (*TencentAdapter) GetURL ¶
func (a *TencentAdapter) GetURL(path string) (string, error)
GetURL generates a presigned URL valid for 1 hour.
func (*TencentAdapter) List ¶
func (a *TencentAdapter) List(path string) ([]*Object, error)
List returns all objects under the specified prefix.