Documentation
¶
Index ¶
- Variables
- func BuildPath(components ...string) string
- func GetContentType(filename string) string
- func RegistProvider(name string, funcProvider FuncNewStore)
- func SplitPath(path string) (dir, file string)
- type BucketInfo
- type Config
- type FuncNewStore
- type GetObjectOptions
- type ObjectInfo
- type Option
- type Provider
- type ProviderType
- type PutObjectOptions
- type RemoveObjectError
- type Store
- func (s *Store) Config() *Config
- func (s *Store) CopyObject(ctx context.Context, srcObject string, dstObject string, srcBucket ...string) error
- func (s *Store) Delete(ctx context.Context, objectPath string, bucket ...string) error
- func (s *Store) DeleteBatch(ctx context.Context, objectPaths []string, bucket ...string) (<-chan RemoveObjectError, error)
- func (s *Store) Download(ctx context.Context, objectPath string, bucket ...string) (io.ReadCloser, error)
- func (s *Store) EnsureBucket(ctx context.Context, bucketName string) error
- func (s *Store) FileExists(ctx context.Context, objectPath string, bucket ...string) (bool, error)
- func (s *Store) GeneratePresignedURL(ctx context.Context, objectPath string, expiry time.Duration, bucket ...string) (string, error)
- func (s *Store) GetObjectInfo(ctx context.Context, objectPath string, bucket ...string) (ObjectInfo, error)
- func (s *Store) ListObjects(ctx context.Context, prefix string, bucket ...string) ([]ObjectInfo, error)
- func (s *Store) ListObjectsChan(ctx context.Context, prefix string, recursive bool, bucket ...string) (<-chan ObjectInfo, error)
- func (s *Store) ListObjectsRecursive(ctx context.Context, prefix string, bucket ...string) ([]ObjectInfo, error)
- func (s *Store) Provider() Provider
- func (s *Store) PutURL(ctx context.Context, bucketName, objectPath string, expirySeconds int) (string, error)
- func (s *Store) RenameObject(ctx context.Context, oldName, newName string, bucket ...string) error
- func (s *Store) Upload(ctx context.Context, objectPath string, data io.Reader, size int64, ...) (string, error)
- func (s *Store) WalkObjects(ctx context.Context, prefix string, fn func(ObjectInfo) error, ...) error
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidConfig = errors.New("invalid storage configuration") ErrProviderNotFound = errors.New("storage provider not found") ErrBucketNotFound = errors.New("bucket not found") ErrObjectNotFound = errors.New("object not found") ErrInvalidObjectName = errors.New("invalid object name") )
Common errors
var (
ErrBucketRequired = errors.New("bucket is required and no default bucket is set")
)
Functions ¶
func GetContentType ¶
GetContentType determines the content type based on file extension
func RegistProvider ¶
func RegistProvider(name string, funcProvider FuncNewStore)
Types ¶
type BucketInfo ¶
type BucketInfo struct {
Name string // Name of the bucket
CreationDate time.Time // Creation date of the bucket
}
BucketInfo contains information about a bucket
type Config ¶
type Config struct {
// Provider type (minio, local, etc.)
Provider ProviderType `json:"provider" yaml:"provider"`
// Common settings
Region string `json:"region" yaml:"region"`
Secure bool `json:"secure" yaml:"secure"`
Timeout time.Duration `json:"timeout" yaml:"timeout"`
// Unified storage settings
// These fields are used across different providers
Endpoint string `json:"endpoint" yaml:"endpoint"`
AccessKey string `json:"access_key" yaml:"access_key"`
SecretKey string `json:"secret_key" yaml:"secret_key"`
SessionToken string `json:"session_token,omitempty" yaml:"session_token,omitempty"`
UseSSL bool `json:"use_ssl" yaml:"use_ssl"`
// Provider-specific settings that don't fit in the common fields
// Local storage specific
BasePath string `json:"base_path,omitempty" yaml:"base_path,omitempty"`
// SFTP specific settings
SSHPort int `json:"ssh_port,omitempty" yaml:"ssh_port,omitempty"` // SSH port (default: 22)
SSHUser string `json:"ssh_user,omitempty" yaml:"ssh_user,omitempty"` // SSH username
SSHPassword string `json:"ssh_password,omitempty" yaml:"ssh_password,omitempty"` // SSH password
SSHPrivateKey string `json:"ssh_private_key,omitempty" yaml:"ssh_private_key,omitempty"` // SSH private key path or content
SSHKeyPassword string `json:"ssh_key_password,omitempty" yaml:"ssh_key_password,omitempty"` // SSH private key password
}
Config represents the unified configuration for all storage providers
type FuncNewStore ¶
type GetObjectOptions ¶
type GetObjectOptions struct {
Range string // Range of bytes to download
MatchETag string // Download object if ETag matches
NotMatchETag string // Download object if ETag doesn't match
}
GetObjectOptions specifies options for GetObject operation
type ObjectInfo ¶
type ObjectInfo struct {
Bucket string // Bucket name
Name string // Object name
ETag string // ETag of the object
Size int64 // Size of the object
LastModified time.Time // Last modified time of the object
ContentType string // Content type of the object
Metadata map[string]string // User-defined metadata
}
ObjectInfo contains information about an object
type Option ¶
type Option func(*Store)
func WithBucket ¶
WithBucket sets the default bucket for all operations If ensureExists is true, it will ensure the bucket exists when the store is created
type Provider ¶
type Provider interface {
// Bucket operations
BucketExists(ctx context.Context, bucketName string) (bool, error)
CreateBucket(ctx context.Context, bucketName string) error
RemoveBucket(ctx context.Context, bucketName string) error
ListBuckets(ctx context.Context) ([]BucketInfo, error)
// Object operations
PutObject(ctx context.Context, bucketName, objectName string, reader io.Reader, objectSize int64, opts PutObjectOptions) (ObjectInfo, error)
GetObject(ctx context.Context, bucketName, objectName string, opts GetObjectOptions) (io.ReadCloser, ObjectInfo, error)
StatObject(ctx context.Context, bucketName, objectName string) (ObjectInfo, error)
RemoveObject(ctx context.Context, bucketName, objectName string) error
ListObjects(ctx context.Context, bucketName, prefix string, recursive bool) <-chan ObjectInfo
// Batch operations
RemoveObjects(ctx context.Context, bucketName string, objectNames []string) <-chan RemoveObjectError
// Copy/Rename operations
CopyObject(ctx context.Context, srcBucket, srcObject, dstBucket, dstObject string) (ObjectInfo, error)
// Presigned URL operations
PresignedGetObject(ctx context.Context, bucketName, objectName string, expires time.Duration) (string, error)
PresignedPutObject(ctx context.Context, bucketName, objectName string, expires time.Duration) (string, error)
}
Provider defines the interface for cloud storage operations
type ProviderType ¶
type ProviderType string
ProviderType represents the type of storage provider
const ( // ProviderMinio represents MinIO/S3 compatible storage ProviderMinio ProviderType = "minio" // ProviderLocal represents local file system storage ProviderLocal ProviderType = "local" // ProviderHuaweiOBS represents Huawei Cloud Object Storage Service ProviderHuaweiOBS ProviderType = "huawei_obs" // ProviderAliyunOSS represents Alibaba Cloud Object Storage Service ProviderAliyunOSS ProviderType = "aliyun_oss" // ProviderNFS represents NFS (Network File System) storage ProviderNFS ProviderType = "nfs" // ProviderSFTP represents SFTP (SSH File Transfer Protocol) storage ProviderSFTP ProviderType = "sftp" )
type PutObjectOptions ¶
type PutObjectOptions struct {
ContentType string // Content type of the object
Metadata map[string]string // User-defined metadata
}
PutObjectOptions specifies options for PutObject operation
type RemoveObjectError ¶ added in v1.0.0
type RemoveObjectError struct {
ObjectName string // Name of the object
Error error // Error that occurred during removal
}
RemoveObjectError contains information about a failed object removal
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store provides a unified interface for cloud storage operations
func (*Store) CopyObject ¶ added in v1.0.0
func (s *Store) CopyObject(ctx context.Context, srcObject string, dstObject string, srcBucket ...string) error
CopyObject copies an object from source to destination If srcBucket or dstBucket is empty, the default bucket will be used
func (*Store) Delete ¶
Delete deletes a file from the specified bucket and object path If bucket is nil, the default bucket will be used if set
func (*Store) DeleteBatch ¶ added in v1.0.0
func (s *Store) DeleteBatch(ctx context.Context, objectPaths []string, bucket ...string) (<-chan RemoveObjectError, error)
DeleteBatch deletes multiple files from the specified bucket Returns a channel of RemoveObjectError for any failures If bucket is nil, the default bucket will be used if set
func (*Store) Download ¶
func (s *Store) Download(ctx context.Context, objectPath string, bucket ...string) (io.ReadCloser, error)
Download downloads a file from the specified bucket and object path If bucket is nil, the default bucket will be used if set
func (*Store) EnsureBucket ¶
EnsureBucket ensures that a bucket exists, creating it if necessary
func (*Store) FileExists ¶
FileExists checks if a file exists
func (*Store) GeneratePresignedURL ¶
func (s *Store) GeneratePresignedURL(ctx context.Context, objectPath string, expiry time.Duration, bucket ...string) (string, error)
GeneratePresignedURL generates a presigned URL for the given object If bucket is nil, the default bucket will be used if set
func (*Store) GetObjectInfo ¶
func (s *Store) GetObjectInfo(ctx context.Context, objectPath string, bucket ...string) (ObjectInfo, error)
GetObjectInfo gets metadata for an object If bucket is nil, the default bucket will be used if set
func (*Store) ListObjects ¶
func (s *Store) ListObjects(ctx context.Context, prefix string, bucket ...string) ([]ObjectInfo, error)
ListObjects lists objects in a bucket with the given prefix (non-recursive) If bucket is nil, the default bucket will be used if set
func (*Store) ListObjectsChan ¶ added in v1.0.0
func (s *Store) ListObjectsChan(ctx context.Context, prefix string, recursive bool, bucket ...string) (<-chan ObjectInfo, error)
ListObjectsChan returns a channel of objects for streaming iteration If bucket is nil, the default bucket will be used if set
func (*Store) ListObjectsRecursive ¶ added in v1.0.0
func (s *Store) ListObjectsRecursive(ctx context.Context, prefix string, bucket ...string) ([]ObjectInfo, error)
ListObjectsRecursive lists objects in a bucket with the given prefix recursively If bucket is nil, the default bucket will be used if set
func (*Store) PutURL ¶
func (s *Store) PutURL(ctx context.Context, bucketName, objectPath string, expirySeconds int) (string, error)
PutURL generates a presigned URL for uploading an object
func (*Store) RenameObject ¶ added in v1.0.0
RenameObject renames an object within the same bucket If bucket is nil, the default bucket will be used if set
func (*Store) Upload ¶
func (s *Store) Upload(ctx context.Context, objectPath string, data io.Reader, size int64, contentType string, bucket ...string) (string, error)
Upload uploads a file to the specified bucket and object path If bucket is nil, the default bucket will be used if set
func (*Store) WalkObjects ¶ added in v1.0.0
func (s *Store) WalkObjects(ctx context.Context, prefix string, fn func(ObjectInfo) error, bucket ...string) error
WalkObjects iterates through objects with the given prefix and calls fn for each object If bucket is nil, the default bucket will be used if set