Documentation
¶
Overview ¶
Package oss provides a unified object storage abstraction layer.
The core package contains only the shared interface, configuration, registry, validation, and local filesystem implementation. Cloud providers live in provider subpackages and must be imported explicitly for registration.
Index ¶
- func ContentType(ext string) string
- func RegisterDriver(driver Driver)
- func RegisteredDrivers() []string
- type Config
- type Driver
- type FileSystem
- 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 Object
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContentType ¶ added in v0.2.5
ContentType returns the MIME content type for the given file extension. Returns an empty string if the extension is not recognized.
func RegisterDriver ¶
func RegisterDriver(driver Driver)
RegisterDriver registers a storage driver. Typically called in the driver package's init function.
func RegisteredDrivers ¶ added in v0.2.5
func RegisteredDrivers() []string
RegisteredDrivers returns a snapshot of registered provider names.
Types ¶
type Config ¶
type Config struct {
Provider string `json:"provider" yaml:"provider"` // Storage provider: minio, s3, aliyun, azure, tencent, qiniu, gcs, synology, filesystem (aliases: oss/cos/r2/b2)
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 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, error)
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