github.com/sandwich-go/boost@v1.3.29/misc/cloud/cloud.go (about) 1 package cloud 2 3 import ( 4 "context" 5 "errors" 6 "io" 7 "time" 8 ) 9 10 var ( 11 // ErrRegionShouldNotEmptyForS3 s3 的 region 必须进行设置,否则返回该错误 12 ErrRegionShouldNotEmptyForS3 = errors.New("region should not empty for s3") 13 // ErrUnknownStorageType 未知的 StorageType 14 ErrUnknownStorageType = errors.New("unknown storage type") 15 ) 16 17 // ObjectInfo container for object metadata. 18 type ObjectInfo struct { 19 // An ETag is optionally set to md5sum of an object. In case of multipart objects, 20 // ETag is of the form MD5SUM-N where MD5SUM is md5sum of all individual md5sums of 21 // each parts concatenated into one string. 22 ETag string `json:"etag"` 23 Key string `json:"name"` // Name of the object 24 LastModified time.Time `json:"lastModified"` // Date and time the object was last modified. 25 Size int64 `json:"size"` // Size in bytes of the object. 26 ContentType string `json:"contentType"` // A standard MIME type describing the format of the object data. 27 } 28 29 // Storage 存储器 30 type Storage interface { 31 // GetRootUrl 获取 root url,不同的 StorageType,拥有不同的 root url 32 GetRootUrl() string 33 // ResolveObjectName 解析 objectName 34 ResolveObjectName(rawUrl string) (string, error) 35 36 // DelObject 通过 objectName 删除指定的 object 37 DelObject(ctx context.Context, objectName string) error 38 // PutObject 将 object 存放至 Storage 中 39 // PutObject Uploads objects that are less than 128MiB in a single PUT operation.Wr481iDXfbN1VntumTyHPM7f4IKDvTr4 40 // For objects that are greater than 128MiB in size, PutObject seamlessly 41 // uploads the object as parts of 128MiB or more depending on the actual file size. 42 // The max upload size for an object is 5TB. 43 PutObject(ctx context.Context, objectName string, reader io.Reader, objectSize int, options ...PutOption) (err error) 44 // StatObject 通过 objectName 获取 object 元信息 ObjectInfo 45 StatObject(ctx context.Context, objectName string) (ObjectInfo, error) 46 // ListObjects 通过前缀批量获取 object 元信息 ObjectInfo 47 ListObjects(ctx context.Context, prefix string) <-chan ObjectInfo 48 // GetObject 通过 objectName 获取 object 49 GetObject(ctx context.Context, objectName string) (reader io.Reader, err error) 50 // CopyObject 拷贝名为 srcObjectName 的 object 至 destObjectName 51 CopyObject(ctx context.Context, destObjectName, srcObjectName string) error 52 }