Documentation
¶
Index ¶
- type AWSStorage
- func (s *AWSStorage) Delete(ctx context.Context, bucketName, objectKey string) error
- func (s *AWSStorage) Download(ctx context.Context, bucketName, objectKey string) (io.ReadCloser, error)
- func (s *AWSStorage) GetURL(ctx context.Context, bucketName, objectKey string, expire time.Duration) (string, error)
- func (s *AWSStorage) ListObjects(ctx context.Context, bucketName, prefix string) ([]ObjectInfo, error)
- func (s *AWSStorage) Upload(ctx context.Context, bucketName, objectKey string, reader io.Reader, ...) error
- type AliyunStorage
- func (s *AliyunStorage) Delete(ctx context.Context, bucketName, objectKey string) error
- func (s *AliyunStorage) Download(ctx context.Context, bucketName, objectKey string) (io.ReadCloser, error)
- func (s *AliyunStorage) GetURL(ctx context.Context, bucketName, objectKey string, expire time.Duration) (string, error)
- func (s *AliyunStorage) ListObjects(ctx context.Context, bucketName, prefix string) ([]ObjectInfo, error)
- func (s *AliyunStorage) Upload(ctx context.Context, bucketName, objectKey string, reader io.Reader, ...) error
- type Config
- type Factory
- type HuaweiStorage
- func (s *HuaweiStorage) Delete(ctx context.Context, bucketName, objectKey string) error
- func (s *HuaweiStorage) Download(ctx context.Context, bucketName, objectKey string) (io.ReadCloser, error)
- func (s *HuaweiStorage) GetURL(ctx context.Context, bucketName, objectKey string, expire time.Duration) (string, error)
- func (s *HuaweiStorage) ListObjects(ctx context.Context, bucketName, prefix string) ([]ObjectInfo, error)
- func (s *HuaweiStorage) Upload(ctx context.Context, bucketName, objectKey string, reader io.Reader, ...) error
- type ObjectInfo
- type Provider
- type ProviderType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AWSStorage ¶
type AWSStorage struct {
// contains filtered or unexported fields
}
AWSStorage AWS S3存储实现
func NewAWSStorage ¶
func NewAWSStorage(cfg Config) (*AWSStorage, error)
NewAWSStorage 创建AWS S3存储客户端
func (*AWSStorage) Delete ¶
func (s *AWSStorage) Delete(ctx context.Context, bucketName, objectKey string) error
Delete 从AWS S3删除文件
func (*AWSStorage) Download ¶
func (s *AWSStorage) Download(ctx context.Context, bucketName, objectKey string) (io.ReadCloser, error)
Download 从AWS S3下载文件
func (*AWSStorage) GetURL ¶
func (s *AWSStorage) GetURL(ctx context.Context, bucketName, objectKey string, expire time.Duration) (string, error)
GetURL 获取AWS S3文件URL
func (*AWSStorage) ListObjects ¶
func (s *AWSStorage) ListObjects(ctx context.Context, bucketName, prefix string) ([]ObjectInfo, error)
ListObjects 列出AWS S3存储桶中的对象
type AliyunStorage ¶
type AliyunStorage struct {
// contains filtered or unexported fields
}
AliyunStorage 阿里云OSS存储实现
func NewAliyunStorage ¶
func NewAliyunStorage(config Config) (*AliyunStorage, error)
NewAliyunStorage 创建阿里云存储客户端
func (*AliyunStorage) Delete ¶
func (s *AliyunStorage) Delete(ctx context.Context, bucketName, objectKey string) error
Delete 从阿里云OSS删除文件
func (*AliyunStorage) Download ¶
func (s *AliyunStorage) Download(ctx context.Context, bucketName, objectKey string) (io.ReadCloser, error)
Download 从阿里云OSS下载文件
func (*AliyunStorage) GetURL ¶
func (s *AliyunStorage) GetURL(ctx context.Context, bucketName, objectKey string, expire time.Duration) (string, error)
GetURL 获取阿里云OSS文件URL
func (*AliyunStorage) ListObjects ¶
func (s *AliyunStorage) ListObjects(ctx context.Context, bucketName, prefix string) ([]ObjectInfo, error)
ListObjects 列出阿里云OSS存储桶中的对象
type Factory ¶
type Factory struct {
// contains filtered or unexported fields
}
Factory 存储提供商工厂
func NewFactory ¶
func NewFactory(providerType ProviderType, config Config) *Factory
NewFactory 创建存储工厂
type HuaweiStorage ¶
type HuaweiStorage struct {
// contains filtered or unexported fields
}
HuaweiStorage 华为云OBS存储实现 注意:由于我们没有直接引入华为云SDK,这里提供一个基本实现框架 实际项目中,您需要添加huaweicloud-sdk-go-obs依赖并完善此实现
func NewHuaweiStorage ¶
func NewHuaweiStorage(config Config) (*HuaweiStorage, error)
NewHuaweiStorage 创建华为云OBS存储客户端
func (*HuaweiStorage) Delete ¶
func (s *HuaweiStorage) Delete(ctx context.Context, bucketName, objectKey string) error
Delete 从华为云OBS删除文件
func (*HuaweiStorage) Download ¶
func (s *HuaweiStorage) Download(ctx context.Context, bucketName, objectKey string) (io.ReadCloser, error)
Download 从华为云OBS下载文件
func (*HuaweiStorage) GetURL ¶
func (s *HuaweiStorage) GetURL(ctx context.Context, bucketName, objectKey string, expire time.Duration) (string, error)
GetURL 获取华为云OBS文件URL
func (*HuaweiStorage) ListObjects ¶
func (s *HuaweiStorage) ListObjects(ctx context.Context, bucketName, prefix string) ([]ObjectInfo, error)
ListObjects 列出华为云OBS存储桶中的对象
type ObjectInfo ¶
type ObjectInfo struct {
Key string // 对象键名
Size int64 // 对象大小(字节)
LastModified time.Time // 最后修改时间
ContentType string // 内容类型
ETag string // ETag标识
}
ObjectInfo 表示存储对象的基本信息
type Provider ¶
type Provider interface {
// Upload 上传文件到云存储
Upload(ctx context.Context, bucketName, objectKey string, reader io.Reader, contentType string) error
// Download 从云存储下载文件
Download(ctx context.Context, bucketName, objectKey string) (io.ReadCloser, error)
// Delete 从云存储删除文件
Delete(ctx context.Context, bucketName, objectKey string) error
// GetURL 获取访问URL
GetURL(ctx context.Context, bucketName, objectKey string, expire time.Duration) (string, error)
// ListObjects 列出存储桶中的对象
ListObjects(ctx context.Context, bucketName, prefix string) ([]ObjectInfo, error)
}
Provider 定义对象存储服务的通用接口
type ProviderType ¶
type ProviderType string
ProviderType 定义云存储提供商类型
const ( // ProviderAWS AWS S3存储 ProviderAWS ProviderType = "aws" // ProviderAliyun 阿里云OSS存储 ProviderAliyun ProviderType = "aliyun" // ProviderHuawei 华为云OBS存储 ProviderHuawei ProviderType = "huawei" )
Click to show internal directories.
Click to hide internal directories.