Documentation
¶
Index ¶
- Variables
- type AWSConfig
- type AWSStore
- func (s *AWSStore) BucketExists(ctx context.Context, bucket string) (bool, error)
- func (s *AWSStore) Close() error
- func (s *AWSStore) DeleteObject(ctx context.Context, bucket, key string) error
- func (s *AWSStore) GetObject(ctx context.Context, bucket, key string) (io.ReadCloser, error)
- func (s *AWSStore) ListObjects(ctx context.Context, bucket, prefix string, opts ...ListOption) ([]ObjectInfo, error)
- func (s *AWSStore) PresignedGetObject(ctx context.Context, bucket, key string, expiry time.Duration) (string, error)
- func (s *AWSStore) PresignedPutObject(ctx context.Context, bucket, key string, expiry time.Duration, ...) (string, error)
- func (s *AWSStore) PutObject(ctx context.Context, bucket, key string, data io.Reader, opts ...PutOption) error
- func (s *AWSStore) StatObject(ctx context.Context, bucket, key string) (*ObjectInfo, error)
- type AliyunConfig
- type AliyunStore
- func (s *AliyunStore) BucketExists(ctx context.Context, bucket string) (bool, error)
- func (s *AliyunStore) Close() error
- func (s *AliyunStore) DeleteObject(ctx context.Context, bucket, key string) error
- func (s *AliyunStore) GetObject(ctx context.Context, bucket, key string) (io.ReadCloser, error)
- func (s *AliyunStore) ListObjects(ctx context.Context, bucket, prefix string, opts ...ListOption) ([]ObjectInfo, error)
- func (s *AliyunStore) PresignedGetObject(ctx context.Context, bucket, key string, expiry time.Duration) (string, error)
- func (s *AliyunStore) PresignedPutObject(ctx context.Context, bucket, key string, expiry time.Duration, ...) (string, error)
- func (s *AliyunStore) PutObject(ctx context.Context, bucket, key string, data io.Reader, opts ...PutOption) error
- func (s *AliyunStore) StatObject(ctx context.Context, bucket, key string) (*ObjectInfo, error)
- type Config
- type IObjectStore
- func NewAWSStore(cfg *AWSConfig, enableTrace bool) (IObjectStore, error)
- func NewAliyunStore(cfg *AliyunConfig, enableTrace bool) (IObjectStore, error)
- func NewMinIOStore(cfg *MinIOConfig, enableTrace bool) (IObjectStore, error)
- func NewTencentStore(cfg *TencentConfig, enableTrace bool) (IObjectStore, error)
- type LifecycleManager
- type LifecycleRule
- type ListOption
- type MinIOConfig
- type MinIOStore
- func (s *MinIOStore) BucketExists(ctx context.Context, bucket string) (bool, error)
- func (s *MinIOStore) Close() error
- func (s *MinIOStore) DeleteObject(ctx context.Context, bucket, key string) error
- func (s *MinIOStore) GetObject(ctx context.Context, bucket, key string) (io.ReadCloser, error)
- func (s *MinIOStore) ListObjects(ctx context.Context, bucket, prefix string, opts ...ListOption) ([]ObjectInfo, error)
- func (s *MinIOStore) PresignedGetObject(ctx context.Context, bucket, key string, expiry time.Duration) (string, error)
- func (s *MinIOStore) PresignedPutObject(ctx context.Context, bucket, key string, expiry time.Duration, ...) (string, error)
- func (s *MinIOStore) PutObject(ctx context.Context, bucket, key string, data io.Reader, opts ...PutOption) error
- func (s *MinIOStore) StatObject(ctx context.Context, bucket, key string) (*ObjectInfo, error)
- type MultipartUploader
- type ObjectInfo
- type Options
- type PartInfo
- type Provider
- type PutOption
- type StoreConfig
- type StoreFactory
- type StoreOptions
- type TencentConfig
- type TencentStore
- func (s *TencentStore) BucketExists(ctx context.Context, bucket string) (bool, error)
- func (s *TencentStore) Close() error
- func (s *TencentStore) DeleteObject(ctx context.Context, bucket, key string) error
- func (s *TencentStore) GetObject(ctx context.Context, bucket, key string) (io.ReadCloser, error)
- func (s *TencentStore) ListObjects(ctx context.Context, bucket, prefix string, opts ...ListOption) ([]ObjectInfo, error)
- func (s *TencentStore) PresignedGetObject(ctx context.Context, bucket, key string, expiry time.Duration) (string, error)
- func (s *TencentStore) PresignedPutObject(ctx context.Context, bucket, key string, expiry time.Duration, ...) (string, error)
- func (s *TencentStore) PutObject(ctx context.Context, bucket, key string, data io.Reader, opts ...PutOption) error
- func (s *TencentStore) StatObject(ctx context.Context, bucket, key string) (*ObjectInfo, error)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrBucketNotExist 存储桶不存在 ErrBucketNotExist = errors.New("bucket not exist") // ErrObjectNotFound 对象不存在 ErrObjectNotFound = errors.New("object not found") ErrUnauthorized = errors.New("unauthorized") // ErrAccessDenied 访问被拒绝 ErrAccessDenied = errors.New("access denied") // ErrInvalidConfig 无效配置 ErrInvalidConfig = errors.New("invalid config") // ErrStoreNotFound 存储适配器未找到 ErrStoreNotFound = errors.New("store not found") // ErrNotSupported 不支持的操作 ErrNotSupported = errors.New("operation not supported") )
统一错误定义
Functions ¶
This section is empty.
Types ¶
type AWSConfig ¶
type AWSConfig struct {
Region string `yaml:"region" env:"OSS_AWS_REGION" required:"true"`
AccessKeyID string `yaml:"access_key_id" env:"OSS_AWS_ACCESS_KEY_ID" required:"true"`
SecretAccessKey string `yaml:"secret_access_key" env:"OSS_AWS_SECRET_ACCESS_KEY" required:"true"`
BucketName string `yaml:"bucket_name" env:"OSS_AWS_BUCKET_NAME" required:"true"`
Endpoint string `yaml:"endpoint,omitempty" env:"OSS_AWS_ENDPOINT"` // 可选,用于兼容 S3 的服务
UseSSL bool `yaml:"use_ssl" env:"OSS_AWS_USE_SSL" default:"true"`
}
AWSConfig AWS S3 配置
type AWSStore ¶
type AWSStore struct {
// contains filtered or unexported fields
}
AWSStore AWS S3 适配器
func (*AWSStore) BucketExists ¶
BucketExists 检查存储桶是否存在
func (*AWSStore) DeleteObject ¶
DeleteObject 删除对象
func (*AWSStore) ListObjects ¶
func (s *AWSStore) ListObjects(ctx context.Context, bucket, prefix string, opts ...ListOption) ([]ObjectInfo, error)
ListObjects 列出对象
func (*AWSStore) PresignedGetObject ¶
func (s *AWSStore) PresignedGetObject(ctx context.Context, bucket, key string, expiry time.Duration) (string, error)
PresignedGetObject 生成预签名下载 URL
func (*AWSStore) PresignedPutObject ¶
func (s *AWSStore) PresignedPutObject(ctx context.Context, bucket, key string, expiry time.Duration, contentType string) (string, error)
PresignedPutObject 生成预签名上传 URL
func (*AWSStore) PutObject ¶
func (s *AWSStore) PutObject(ctx context.Context, bucket, key string, data io.Reader, opts ...PutOption) error
PutObject 上传对象
func (*AWSStore) StatObject ¶
StatObject 获取对象信息
type AliyunConfig ¶
type AliyunConfig struct {
Endpoint string `yaml:"endpoint" env:"OSS_ALIYUN_ENDPOINT" required:"true"`
AccessKeyID string `yaml:"access_key_id" env:"OSS_ALIYUN_ACCESS_KEY_ID" required:"true"`
SecretAccessKey string `yaml:"secret_access_key" env:"OSS_ALIYUN_SECRET_ACCESS_KEY" required:"true"`
BucketName string `yaml:"bucket_name" env:"OSS_ALIYUN_BUCKET_NAME" required:"true"`
UseSSL bool `yaml:"use_ssl" env:"OSS_ALIYUN_USE_SSL" default:"true"`
}
AliyunConfig 阿里云 OSS 配置
type AliyunStore ¶
type AliyunStore struct {
// contains filtered or unexported fields
}
AliyunStore 阿里云 OSS 适配器
func (*AliyunStore) BucketExists ¶
BucketExists 检查存储桶是否存在
func (*AliyunStore) DeleteObject ¶
func (s *AliyunStore) DeleteObject(ctx context.Context, bucket, key string) error
DeleteObject 删除对象
func (*AliyunStore) GetObject ¶
func (s *AliyunStore) GetObject(ctx context.Context, bucket, key string) (io.ReadCloser, error)
GetObject 下载对象
func (*AliyunStore) ListObjects ¶
func (s *AliyunStore) ListObjects(ctx context.Context, bucket, prefix string, opts ...ListOption) ([]ObjectInfo, error)
ListObjects 列出对象
func (*AliyunStore) PresignedGetObject ¶
func (s *AliyunStore) PresignedGetObject(ctx context.Context, bucket, key string, expiry time.Duration) (string, error)
PresignedGetObject 生成预签名下载 URL
func (*AliyunStore) PresignedPutObject ¶
func (s *AliyunStore) PresignedPutObject(ctx context.Context, bucket, key string, expiry time.Duration, contentType string) (string, error)
PresignedPutObject 生成预签名上传 URL
func (*AliyunStore) PutObject ¶
func (s *AliyunStore) PutObject(ctx context.Context, bucket, key string, data io.Reader, opts ...PutOption) error
PutObject 上传对象
func (*AliyunStore) StatObject ¶
func (s *AliyunStore) StatObject(ctx context.Context, bucket, key string) (*ObjectInfo, error)
StatObject 获取对象信息
type Config ¶
type Config struct {
// Enabled 是否启用 OSS(必填)
Enabled bool `yaml:"enabled" env:"OSS_ENABLED" required:"true"`
// Default 默认使用的厂商名称
Default string `yaml:"default" env:"OSS_DEFAULT"`
// Stores 各厂商配置映射
Stores map[string]StoreConfig `yaml:"stores" json:"stores"`
}
Config 多厂商对象存储配置(用于从配置文件创建)
func (*Config) GetStoreConfig ¶
func (c *Config) GetStoreConfig(name string) (*StoreConfig, error)
GetStoreConfig 获取指定厂商的配置
type IObjectStore ¶
type IObjectStore interface {
// PutObject 上传对象
PutObject(ctx context.Context, bucket, key string, data io.Reader, opts ...PutOption) error
// GetObject 下载对象
GetObject(ctx context.Context, bucket, key string) (io.ReadCloser, error)
// DeleteObject 删除对象
DeleteObject(ctx context.Context, bucket, key string) error
// ListObjects 列出对象
ListObjects(ctx context.Context, bucket, prefix string, opts ...ListOption) ([]ObjectInfo, error)
// PresignedGetObject 生成预签名下载 URL
PresignedGetObject(ctx context.Context, bucket, key string, expiry time.Duration) (string, error)
// PresignedPutObject 生成预签名上传 URL
// contentType 用于指定上传时的 Content-Type,如果为空则不在签名中包含 Content-Type
PresignedPutObject(ctx context.Context, bucket, key string, expiry time.Duration, contentType string) (string, error)
// BucketExists 检查存储桶是否存在
BucketExists(ctx context.Context, bucket string) (bool, error)
// StatObject 获取对象信息
StatObject(ctx context.Context, bucket, key string) (*ObjectInfo, error)
// Close 关闭连接
Close() error
}
IObjectStore 对象存储统一接口
func NewAWSStore ¶
func NewAWSStore(cfg *AWSConfig, enableTrace bool) (IObjectStore, error)
NewAWSStore 创建 AWS S3 适配器
func NewAliyunStore ¶
func NewAliyunStore(cfg *AliyunConfig, enableTrace bool) (IObjectStore, error)
NewAliyunStore 创建阿里云 OSS 适配器
func NewMinIOStore ¶
func NewMinIOStore(cfg *MinIOConfig, enableTrace bool) (IObjectStore, error)
NewMinIOStore 创建 MinIO 适配器
func NewTencentStore ¶
func NewTencentStore(cfg *TencentConfig, enableTrace bool) (IObjectStore, error)
NewTencentStore 创建腾讯云 COS 适配器
type LifecycleManager ¶
type LifecycleManager interface {
// SetLifecycle 设置生命周期规则
SetLifecycle(ctx context.Context, bucket string, rules []LifecycleRule) error
}
LifecycleManager 生命周期管理接口(可选扩展)
type LifecycleRule ¶
LifecycleRule 生命周期规则
type MinIOConfig ¶
type MinIOConfig struct {
Endpoint string `yaml:"endpoint" env:"OSS_MINIO_ENDPOINT" required:"true"`
AccessKeyID string `yaml:"access_key_id" env:"OSS_MINIO_ACCESS_KEY_ID" required:"true"`
SecretAccessKey string `yaml:"secret_access_key" env:"OSS_MINIO_SECRET_ACCESS_KEY" required:"true"`
BucketName string `yaml:"bucket_name" env:"OSS_MINIO_BUCKET_NAME" required:"true"`
UseSSL bool `yaml:"use_ssl" env:"OSS_MINIO_USE_SSL" default:"false"`
Region string `yaml:"region,omitempty" env:"OSS_MINIO_REGION"` // 可选,默认 us-east-1
}
MinIOConfig MinIO 配置
type MinIOStore ¶
type MinIOStore struct {
// contains filtered or unexported fields
}
MinIOStore MinIO 适配器(使用 S3 兼容协议)
func (*MinIOStore) BucketExists ¶
BucketExists 检查存储桶是否存在
func (*MinIOStore) DeleteObject ¶
func (s *MinIOStore) DeleteObject(ctx context.Context, bucket, key string) error
DeleteObject 删除对象
func (*MinIOStore) GetObject ¶
func (s *MinIOStore) GetObject(ctx context.Context, bucket, key string) (io.ReadCloser, error)
GetObject 下载对象
func (*MinIOStore) ListObjects ¶
func (s *MinIOStore) ListObjects(ctx context.Context, bucket, prefix string, opts ...ListOption) ([]ObjectInfo, error)
ListObjects 列出对象
func (*MinIOStore) PresignedGetObject ¶
func (s *MinIOStore) PresignedGetObject(ctx context.Context, bucket, key string, expiry time.Duration) (string, error)
PresignedGetObject 生成预签名下载 URL
func (*MinIOStore) PresignedPutObject ¶
func (s *MinIOStore) PresignedPutObject(ctx context.Context, bucket, key string, expiry time.Duration, contentType string) (string, error)
PresignedPutObject 生成预签名上传 URL
func (*MinIOStore) PutObject ¶
func (s *MinIOStore) PutObject(ctx context.Context, bucket, key string, data io.Reader, opts ...PutOption) error
PutObject 上传对象
func (*MinIOStore) StatObject ¶
func (s *MinIOStore) StatObject(ctx context.Context, bucket, key string) (*ObjectInfo, error)
StatObject 获取对象信息
type MultipartUploader ¶
type MultipartUploader interface {
// CreateMultipartUpload 创建分块上传
CreateMultipartUpload(ctx context.Context, bucket, key string) (string, error)
// UploadPart 上传分块
UploadPart(ctx context.Context, bucket, key, uploadId string, partNumber int, data io.Reader) (PartInfo, error)
// CompleteMultipartUpload 完成分块上传
CompleteMultipartUpload(ctx context.Context, bucket, key, uploadId string, parts []PartInfo) error
}
MultipartUploader 大文件分块上传接口(可选扩展)
type ObjectInfo ¶
type ObjectInfo struct {
Key string
Size int64
LastModified time.Time
ContentType string
ETag string
}
ObjectInfo 对象信息(统一接口,不依赖 AWS SDK 类型)
type Options ¶
type Options struct {
// Enabled 是否启用 OSS
Enabled bool
// Default 默认使用的厂商名称
Default string
// Stores 各厂商配置映射
Stores map[string]StoreOptions
}
Options 统一的 OSS 配置选项(内部使用)
type Provider ¶
type Provider string
Provider 对象存储服务提供商
const ( // ProviderAWS AWS S3 ProviderAWS Provider = "aws" // ProviderAliyun 阿里云 OSS ProviderAliyun Provider = "aliyun" // ProviderTencent 腾讯云 COS ProviderTencent Provider = "tencent" // ProviderMinIO MinIO 服务器 ProviderMinIO Provider = "minio" // ProviderCustom 自定义端点 ProviderCustom Provider = "custom" )
type StoreConfig ¶
type StoreConfig struct {
// Enabled 是否启用此存储(必填)
Enabled bool `yaml:"enabled" env:"OSS_STORE_ENABLED" required:"true"`
// Type 厂商类型:aliyun, aws, tencent, minio
Type string `yaml:"type" env:"OSS_STORE_TYPE" required:"true"`
// Aliyun 阿里云 OSS 配置
Aliyun *AliyunConfig `yaml:"aliyun,omitempty" json:"aliyun,omitempty"`
// AWS AWS S3 配置
AWS *AWSConfig `yaml:"aws,omitempty" json:"aws,omitempty"`
// Tencent 腾讯云 COS 配置
Tencent *TencentConfig `yaml:"tencent,omitempty" json:"tencent,omitempty"`
// MinIO MinIO 配置
MinIO *MinIOConfig `yaml:"minio,omitempty" json:"minio,omitempty"`
// EnableTrace 是否启用追踪
EnableTrace bool `yaml:"enable_trace" env:"OSS_ENABLE_TRACE" default:"true"`
}
StoreConfig 单个厂商的配置
type StoreFactory ¶
type StoreFactory struct {
// contains filtered or unexported fields
}
StoreFactory 存储工厂,管理多个对象存储适配器
func NewFromConfig ¶
func NewFromConfig(cfg *Config) (*StoreFactory, error)
NewFromConfig 从配置创建存储工厂(便捷方法)
func NewStoreFactory ¶
func NewStoreFactory(cfg *Config) (*StoreFactory, error)
NewStoreFactory 创建新的存储工厂
func (*StoreFactory) Get ¶
func (f *StoreFactory) Get(name string) (IObjectStore, error)
Get 获取指定名称的存储适配器
func (*StoreFactory) GetDefault ¶
func (f *StoreFactory) GetDefault() (IObjectStore, error)
GetDefault 获取默认存储适配器
func (*StoreFactory) Register ¶
func (f *StoreFactory) Register(name string, store IObjectStore)
Register 注册存储适配器
type StoreOptions ¶
type StoreOptions struct {
// Enabled 是否启用此存储
Enabled bool
// Type 厂商类型
Type Provider
// Aliyun 阿里云 OSS 配置
Aliyun *AliyunConfig
// AWS AWS S3 配置
AWS *AWSConfig
// Tencent 腾讯云 COS 配置
Tencent *TencentConfig
// MinIO MinIO 配置
MinIO *MinIOConfig
// EnableTrace 是否启用追踪
EnableTrace bool
}
StoreOptions 单个厂商的配置选项(内部使用)
type TencentConfig ¶
type TencentConfig struct {
Region string `yaml:"region" env:"OSS_TENCENT_REGION" required:"true"`
SecretID string `yaml:"secret_id" env:"OSS_TENCENT_SECRET_ID" required:"true"`
SecretKey string `yaml:"secret_key" env:"OSS_TENCENT_SECRET_KEY" required:"true"`
BucketName string `yaml:"bucket_name" env:"OSS_TENCENT_BUCKET_NAME" required:"true"`
UseSSL bool `yaml:"use_ssl" env:"OSS_TENCENT_USE_SSL" default:"true"`
}
TencentConfig 腾讯云 COS 配置
type TencentStore ¶
type TencentStore struct {
// contains filtered or unexported fields
}
TencentStore 腾讯云 COS 适配器
func (*TencentStore) BucketExists ¶
BucketExists 检查存储桶是否存在
func (*TencentStore) DeleteObject ¶
func (s *TencentStore) DeleteObject(ctx context.Context, bucket, key string) error
DeleteObject 删除对象
func (*TencentStore) GetObject ¶
func (s *TencentStore) GetObject(ctx context.Context, bucket, key string) (io.ReadCloser, error)
GetObject 下载对象
func (*TencentStore) ListObjects ¶
func (s *TencentStore) ListObjects(ctx context.Context, bucket, prefix string, opts ...ListOption) ([]ObjectInfo, error)
ListObjects 列出对象
func (*TencentStore) PresignedGetObject ¶
func (s *TencentStore) PresignedGetObject(ctx context.Context, bucket, key string, expiry time.Duration) (string, error)
PresignedGetObject 生成预签名下载 URL
func (*TencentStore) PresignedPutObject ¶
func (s *TencentStore) PresignedPutObject(ctx context.Context, bucket, key string, expiry time.Duration, contentType string) (string, error)
PresignedPutObject 生成预签名上传 URL
func (*TencentStore) PutObject ¶
func (s *TencentStore) PutObject(ctx context.Context, bucket, key string, data io.Reader, opts ...PutOption) error
PutObject 上传对象
func (*TencentStore) StatObject ¶
func (s *TencentStore) StatObject(ctx context.Context, bucket, key string) (*ObjectInfo, error)
StatObject 获取对象信息