storage

package
v1.1.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 7, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

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存储桶中的对象

func (*AWSStorage) Upload

func (s *AWSStorage) Upload(ctx context.Context, bucketName, objectKey string, reader io.Reader, contentType string) error

Upload 上传文件到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存储桶中的对象

func (*AliyunStorage) Upload

func (s *AliyunStorage) Upload(ctx context.Context, bucketName, objectKey string, reader io.Reader, contentType string) error

Upload 上传文件到阿里云OSS

type Config

type Config struct {
	AccessKey string
	SecretKey string
	Region    string
	Endpoint  string
}

Config 存储配置基础结构

type Factory

type Factory struct {
	// contains filtered or unexported fields
}

Factory 存储提供商工厂

func NewFactory

func NewFactory(providerType ProviderType, config Config) *Factory

NewFactory 创建存储工厂

func (*Factory) Create

func (f *Factory) Create() (Provider, error)

Create 创建存储提供商实例

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存储桶中的对象

func (*HuaweiStorage) Upload

func (s *HuaweiStorage) Upload(ctx context.Context, bucketName, objectKey string, reader io.Reader, contentType string) error

Upload 上传文件到华为云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"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL