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 Store
- func (s *Store) Config() *Config
- func (s *Store) Delete(ctx context.Context, objectPath string, bucket ...string) 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) Provider() Provider
- func (s *Store) PutURL(ctx context.Context, bucketName, objectPath string, expirySeconds int) (string, error)
- func (s *Store) Upload(ctx context.Context, objectPath string, data io.Reader, size int64, ...) (string, 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"`
}
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
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
// 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" )
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 Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store provides a unified interface for cloud storage operations
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) 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 If bucket is nil, the default bucket will be used if set