Documentation
¶
Overview ¶
Package storage 提供对象存储统一封装。
支持阿里云 OSS、腾讯云 COS、AWS S3,通过配置自动切换。
基本使用:
storage.Configure(&storage.Config{
Type: storage.TypeOSS,
Bucket: "my-bucket",
Region: "cn-hangzhou",
AccessKeyID: "...",
AccessKeySecret: "...",
})
if err := storage.Upload(ctx, "file.txt", reader); err != nil {
return err
}
SignedURL 适合基础签名访问;如果是客户端直传且需要约束 Content-Type、 checksum、metadata 等条件,应使用 AuthorizeDirectUpload,并在上传完成后 调用 VerifyDirectUploadObject 做对象事实校验。
注意:上传后 checksum 校验是否可用取决于 provider 能否从对象元信息回读 对应算法。
更多信息请参考 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 DirectUploadAuthorization
- type DirectUploadChecksum
- type DirectUploadChecksumAlgorithm
- type DirectUploadConstraints
- type DirectUploadMismatch
- type DirectUploadMode
- type DirectUploadRequest
- type DirectUploadSize
- type DirectUploadVerificationRequest
- type DirectUploadVerificationResult
- type DownloadOption
- type DownloadOptionFunc
- type MultipartUpload
- type ObjectInfo
- type PartInfo
- type SignOption
- type SignOptionFunc
- type UploadOption
- type UploadOptionFunc
Constants ¶
const ( TypeOSS = internal.TypeOSS TypeCOS = internal.TypeCOS TypeS3 = internal.TypeS3 DirectUploadModeAuto = internal.DirectUploadModeAuto DirectUploadModePut = internal.DirectUploadModePut DirectUploadModePost = internal.DirectUploadModePost DirectUploadChecksumMD5 = internal.DirectUploadChecksumMD5 DirectUploadChecksumSHA256 = internal.DirectUploadChecksumSHA256 )
const DefaultSignExpire = 15 * time.Minute
DefaultSignExpire 默认签名过期时间
Variables ¶
var ( ErrMissingClient = errors.New("storage: client not configured") ErrInvalidConfig = errors.New("storage: invalid configuration") ErrUnsupportedType = errors.New("storage: unsupported storage type") ErrObjectNotFound = providers.ErrObjectNotFound ErrBucketNotFound = providers.ErrBucketNotFound ErrAccessDenied = providers.ErrAccessDenied ErrInvalidCredentials = errors.New("storage: invalid credentials") ErrMultipartNotFound = errors.New("storage: multipart upload not found") ErrPartAlreadyExist = errors.New("storage: part already uploaded") ErrInvalidDirectUploadRequest = errors.New("storage: invalid direct upload request") ErrUnsupportedDirectUploadConstraint = providers.ErrUnsupportedDirectUploadConstraint ErrDirectUploadAuthorizationUnsupported = errors.New("storage: direct upload authorization not supported") )
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 DirectUploadAuthorization ¶ added in v1.3.3
type DirectUploadAuthorization = internal.DirectUploadAuthorization
func AuthorizeDirectUpload ¶ added in v1.3.3
func AuthorizeDirectUpload(ctx context.Context, req DirectUploadRequest) (*DirectUploadAuthorization, error)
AuthorizeDirectUpload 生成客户端直传授权结果。
func AuthorizeDirectUploadWithClient ¶ added in v1.3.3
func AuthorizeDirectUploadWithClient(ctx context.Context, c Client, req DirectUploadRequest) (*DirectUploadAuthorization, error)
AuthorizeDirectUploadWithClient 使用指定客户端生成客户端直传授权结果。
type DirectUploadChecksum ¶ added in v1.3.3
type DirectUploadChecksum = internal.DirectUploadChecksum
type DirectUploadChecksumAlgorithm ¶ added in v1.3.3
type DirectUploadChecksumAlgorithm = internal.DirectUploadChecksumAlgorithm
type DirectUploadConstraints ¶ added in v1.3.3
type DirectUploadConstraints = internal.DirectUploadConstraints
type DirectUploadMismatch ¶ added in v1.3.3
type DirectUploadMismatch = internal.DirectUploadMismatch
type DirectUploadMode ¶ added in v1.3.3
type DirectUploadMode = internal.DirectUploadMode
type DirectUploadRequest ¶ added in v1.3.3
type DirectUploadRequest = internal.DirectUploadRequest
type DirectUploadSize ¶ added in v1.3.3
type DirectUploadSize = internal.DirectUploadSize
type DirectUploadVerificationRequest ¶ added in v1.3.3
type DirectUploadVerificationRequest = internal.DirectUploadVerificationRequest
type DirectUploadVerificationResult ¶ added in v1.3.3
type DirectUploadVerificationResult = internal.DirectUploadVerificationResult
func VerifyDirectUploadObject ¶ added in v1.3.3
func VerifyDirectUploadObject(ctx context.Context, req DirectUploadVerificationRequest) (*DirectUploadVerificationResult, error)
VerifyDirectUploadObject 校验客户端直传后的对象状态。
func VerifyDirectUploadObjectWithClient ¶ added in v1.3.3
func VerifyDirectUploadObjectWithClient(ctx context.Context, c Client, req DirectUploadVerificationRequest) (*DirectUploadVerificationResult, error)
VerifyDirectUploadObjectWithClient 使用指定客户端校验客户端直传后的对象状态。
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
func WithMetadata ¶ added in v1.3.3
func WithMetadata(key, value string) UploadOptionFunc
WithMetadata 设置对象 metadata。