Documentation
¶
Overview ¶
Package storage 提供对象存储统一封装。
支持阿里云 OSS、腾讯云 COS、AWS S3,通过配置自动切换。
基本使用:
storage.Configure(&storage.Config{
Type: storage.TypeOSS,
Bucket: "my-bucket",
Region: "cn-hangzhou",
AccessKeyID: "...",
AccessKeySecret: "...",
})
storage.Upload(ctx, "file.txt", reader)
更多信息请参考 README.md
Index ¶
- Constants
- Variables
- func AbortMultipart(ctx context.Context, uploadID string) error
- func AbortMultipartWithClient(ctx context.Context, c Client, uploadID string) error
- func CompleteMultipart(ctx context.Context, uploadID string, parts []*PartInfo, ...) error
- func CompleteMultipartWithClient(ctx context.Context, c Client, uploadID string, parts []*PartInfo, ...) error
- func Configure(cfg *Config) error
- func Delete(ctx context.Context, key string) error
- func DeleteBatch(ctx context.Context, keys []string) error
- func DeleteBatchWithClient(ctx context.Context, c Client, keys []string) error
- func DeleteWithClient(ctx context.Context, c Client, key string) error
- func Download(ctx context.Context, key string, opts ...DownloadOptionFunc) (io.ReadCloser, error)
- func DownloadWithClient(ctx context.Context, c Client, key string, opts ...DownloadOptionFunc) (io.ReadCloser, error)
- func Exists(ctx context.Context, key string) (bool, error)
- func ExistsWithClient(ctx context.Context, c Client, key string) (bool, error)
- func SignedURL(ctx context.Context, key string, expire time.Duration, opts ...SignOptionFunc) (string, error)
- func SignedURLWithClient(ctx context.Context, c Client, key string, expire time.Duration, ...) (string, error)
- func Upload(ctx context.Context, key string, reader io.Reader, opts ...UploadOptionFunc) error
- func UploadWithClient(ctx context.Context, c Client, key string, reader io.Reader, ...) error
- type Client
- type Config
- type DownloadOption
- type DownloadOptionFunc
- type MultipartUpload
- type ObjectInfo
- type PartInfo
- type SignOption
- type SignOptionFunc
- type UploadOption
- type UploadOptionFunc
Constants ¶
View Source
const ( TypeOSS = internal.TypeOSS TypeCOS = internal.TypeCOS TypeS3 = internal.TypeS3 )
View Source
const DefaultSignExpire = 15 * time.Minute
DefaultSignExpire 默认签名过期时间
Variables ¶
View Source
var ( ErrMissingClient = errors.New("storage: client not configured") ErrInvalidConfig = errors.New("storage: invalid configuration") ErrUnsupportedType = errors.New("storage: unsupported storage type") ErrObjectNotFound = errors.New("storage: object not found") ErrBucketNotFound = errors.New("storage: bucket not found") ErrAccessDenied = errors.New("storage: access denied") ErrInvalidCredentials = errors.New("storage: invalid credentials") ErrMultipartNotFound = errors.New("storage: multipart upload not found") ErrPartAlreadyExist = errors.New("storage: part already uploaded") )
Functions ¶
func AbortMultipart ¶
AbortMultipart 中止分片上传
func AbortMultipartWithClient ¶
AbortMultipartWithClient 使用指定客户端中止分片上传
func CompleteMultipart ¶
func CompleteMultipart(ctx context.Context, uploadID string, parts []*PartInfo, opts ...UploadOptionFunc) error
CompleteMultipart 完成分片上传
func CompleteMultipartWithClient ¶
func CompleteMultipartWithClient(ctx context.Context, c Client, uploadID string, parts []*PartInfo, opts ...UploadOptionFunc) error
CompleteMultipartWithClient 使用指定客户端完成分片上传
func DeleteBatchWithClient ¶
DeleteBatchWithClient 使用指定客户端批量删除
func DeleteWithClient ¶
DeleteWithClient 使用指定客户端删除
func Download ¶
func Download(ctx context.Context, key string, opts ...DownloadOptionFunc) (io.ReadCloser, error)
Download 下载文件
func DownloadWithClient ¶
func DownloadWithClient(ctx context.Context, c Client, key string, opts ...DownloadOptionFunc) (io.ReadCloser, error)
DownloadWithClient 使用指定客户端下载
func ExistsWithClient ¶
ExistsWithClient 使用指定客户端检查存在
func SignedURL ¶
func SignedURL(ctx context.Context, key string, expire time.Duration, opts ...SignOptionFunc) (string, error)
SignedURL 生成签名 URL
func SignedURLWithClient ¶
func SignedURLWithClient(ctx context.Context, c Client, key string, expire time.Duration, opts ...SignOptionFunc) (string, error)
SignedURLWithClient 使用指定客户端生成签名 URL
func UploadWithClient ¶
func UploadWithClient(ctx context.Context, c Client, key string, reader io.Reader, opts ...UploadOptionFunc) error
UploadWithClient 使用指定客户端上传
Types ¶
type DownloadOption ¶
type DownloadOption = internal.DownloadOption
type DownloadOptionFunc ¶
type DownloadOptionFunc = internal.DownloadOptionFunc
type MultipartUpload ¶
type MultipartUpload = internal.MultipartUpload
func InitMultipart ¶
func InitMultipart(ctx context.Context, key string, opts ...UploadOptionFunc) (*MultipartUpload, error)
InitMultipart 初始化分片上传
func InitMultipartWithClient ¶
func InitMultipartWithClient(ctx context.Context, c Client, key string, opts ...UploadOptionFunc) (*MultipartUpload, error)
InitMultipartWithClient 使用指定客户端初始化分片上传
type PartInfo ¶
type SignOption ¶
type SignOption = internal.SignOption
type SignOptionFunc ¶
type SignOptionFunc = internal.SignOptionFunc
type UploadOption ¶
type UploadOption = internal.UploadOption
type UploadOptionFunc ¶
type UploadOptionFunc = internal.UploadOptionFunc
func WithContentType ¶
func WithContentType(ct string) UploadOptionFunc
WithContentType 设置 Content-Type
Click to show internal directories.
Click to hide internal directories.