object_storage_sdk

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2020 License: MIT Imports: 8 Imported by: 0

README

object-storage-sdk

多合一对象存储SDK,一次开发,分分钟迁移。目前已支持的主流对象存储有:

为什么又一个SDK

  • 企业用户的对象存储方案是多种多样的,企业服务厂家在给企业进行服务部署时,不可避免要对多种存储方案进行支持。
  • 对象存储厂家迁移时,无可避免要修改系统代码。

注意

项目目前正在开发中,未达到生产环境可用级别

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BucketNotExist = errors.New("bucket doesn't exist")

Functions

func CheckResponse

func CheckResponse(resp *http.Response) error

func FGetObject

func FGetObject(bucket BasicBucket, objectKey string, localFilePath string) error

func FGetObjectWithURL

func FGetObjectWithURL(signedURL, localFilePath string, timeout time.Duration) error

func FPutObject

func FPutObject(ctx context.Context, bucket BasicBucket, objectKey string, localFilePath string) error

func FPutObjectWithURL

func FPutObjectWithURL(signedURL, localFilePath string, timeout time.Duration) error

func GetConfig

func GetConfig(options ...Option) *config

func GetObjectWithURL

func GetObjectWithURL(signedURL string, timeout time.Duration) (io.ReadCloser, *http.Response, error)

func HeadObjectWithURL

func HeadObjectWithURL(signedURL string, timeout time.Duration) (http.Header, error)

func PutObjectWithURL

func PutObjectWithURL(signedURL string, reader io.Reader, timeout time.Duration) (*http.Response, error)

Types

type ACLType

type ACLType string

ACLType bucket/object ACL

const (
	// ACLPrivate definition : private read and write
	ACLPrivate ACLType = "private"

	// ACLPublicRead definition : public read and private write
	ACLPublicRead ACLType = "public-read"

	// ACLPublicReadWrite definition : public read and public write
	ACLPublicReadWrite ACLType = "public-read-write"

	// ACLDefault Object. It's only applicable for object.
	ACLDefault ACLType = "default"
)

type BasicBucket

type BasicBucket interface {
	GetObject(objectKey string) (io.ReadCloser, error)
	HeadObject(objectKey string) (object ObjectMeta, err error)
	ListObjects(objectPrefix string) (objects []ObjectProperty, err error)
	PutObject(objectKey string, reader io.Reader) error
	CopyObject(srcObjectKey, dstObjectKey string) error
	RemoveObject(objectKey string) error
	RemoveObjects(objectKeys []string) error
}

type BasicClient

type BasicClient interface {
	Bucket(bucketName string) (bucket BasicBucket, err error)
	MakeBucket(bucketName string, options ...Option) error
	HeadBucket(bucketName string) error
	GetBucketLocation(bucketName string) (location string, err error)
	ListBucket(options ...Option) (buckets []BucketProperties, err error)
	RemoveBucket(bucketName string) error
	CopyObject(srcBucketName, srcObjectKey, dstBucketName, dstObjectKey string) error
}

type BucketProperties

type BucketProperties struct {
	Name      string
	CreatedAt time.Time
}

type CompletePart

type CompletePart struct {
	PartNumber int
	ETag       string
}

type MultipartUploadAbleBucket

type MultipartUploadAbleBucket interface {
	ListMultipartUploads(objectKeyPrefix string) (uploads []Upload, err error)
	InitMultipartUpload(objectKey string) (uploadId string, err error)
	UploadPart(objectKey, uploadId string, partNum int, reader io.ReadSeeker) (eTag string, err error)
	ListParts(objectKey string, uploadId string) (parts []Part, err error)
	CompleteUploadPart(objectKey string, uploadId string, parts []CompletePart) error
	AbortMultipartUpload(objectKey string, uploadId string) error
}

type MultipartUploadPresignAbleBucket

type MultipartUploadPresignAbleBucket interface {
	PresignUploadPart(objectKey string, uploadId string, partNum int, expiresIn time.Duration) (string, error)
}

type ObjectMeta

type ObjectMeta struct {
	ContentType   string
	ContentLength int
	ETag          string
	LastModified  time.Time
}

func HeaderToObjectMeta

func HeaderToObjectMeta(header http.Header) (objectMeta ObjectMeta, err error)

type ObjectProperty

type ObjectProperty struct {
	ObjectMeta
	ObjectKey string
}

type Option

type Option func(config *config)

func WithACL

func WithACL(aclType ACLType) Option

type Part

type Part struct {
	PartNumber   int
	Size         int
	ETag         string
	LastModified time.Time
}

type PresignAbleBucket

type PresignAbleBucket interface {
	PresignGetObject(objectKey string, expiresIn time.Duration) (signedURL string, err error)
	PresignHeadObject(objectKey string, expiresIn time.Duration) (signedURL string, err error)
	PresignPutObject(objectKey string, expiresIn time.Duration) (signedURL string, err error)
}

type PresignPostAbleBucket

type PresignPostAbleBucket interface {
	PresignPostObject(objectKey string, expiresIn time.Duration) (signedURL, fileField string, formData map[string]string, err error)
}

type Upload

type Upload struct {
	ObjectKey string
	UploadId  string
	Initiated time.Time
}

Directories

Path Synopsis
impl

Jump to

Keyboard shortcuts

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