eoss

package module
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2023 License: Apache-2.0 Imports: 29 Imported by: 0

README

EOSS: Wrapper For Aliyun OSS And Amazon S3

awos for node: https://github.com/shimohq/awos-js

Features

  • enable shards bucket
  • add retry strategy
  • avoid 404 status code:
    • Get(objectName string) (string, error) will return "", nil when object not exist
    • Head(key string, meta []string) (map[string]string, error) will return nil, nil when object not exist

Installing

Use go get to retrieve the SDK to add it to your GOPATH workspace, or project's Go module dependencies.

go get github.com/ego-component/eoss

How to use

config
[storage]
storageType = "oss" # oss|s3
accessKeyID = "xxx"
accessKeySecret = "xxx"
endpoint = "oss-cn-beijing.aliyuncs.com"
bucket = "aaa"
shards = []
[storage.buckets.template] # 可配置多套buckets配置,buckets里的配置会替换上层配置
bucket = "template-bucket"
shards = []
[storage.buckets.fileContent]
bucket = "contents-bucket"
shards = [
 "abcdefghijklmnopqr",
 "stuvwxyz0123456789"
]
import "github.com/ego-component/eoss"

// 单独一个 bucket 配置
client := eoss.Load("storage").Build()
// 多 bucket 配置
client := eoss.Load("storage").Build(eoss.WithBucketKey("template"))

// 带context(可记录链路)
client.WithContext(ctx).Get(key)

Available operations:

WithContext(ctx context.Context) Component
Get(key string, options ...GetOptions) (string, error)
GetBytes(key string, options ...GetOptions) ([]byte, error)
GetAsReader(key string, options ...GetOptions) (io.ReadCloser, error)
GetWithMeta(key string, attributes []string, options ...GetOptions) (io.ReadCloser, map[string]string, error)
Put(key string, reader io.ReadSeeker, meta map[string]string, options ...PutOptions) error
Del(key string) error
DelMulti(keys []string) error
Head(key string, meta []string) (map[string]string, error)
ListObject(key string, prefix string, marker string, maxKeys int, delimiter string) ([]string, error)
SignURL(key string, expired int64) (string, error)
GetAndDecompress(key string) (string, error)
GetAndDecompressAsReader(key string) (io.ReadCloser, error)
CompressAndPut(key string, reader io.ReadSeeker, meta map[string]string, options ...PutOptions) error
Range(key string, offset int64, length int64) (io.ReadCloser, error)
Exists(key string)(bool, error)

Documentation

Index

Constants

View Source
const (
	StorageTypeOSS = "oss"
	StorageTypeS3  = "s3"

	MetaCompressor = "compressor"
)
View Source
const PackageName = "component.eoss"

Variables

View Source
var DefaultGzipCompressor = &GzipCompressor{}

Functions

func DefaultConfig

func DefaultConfig() *config

DefaultConfig 返回默认配置

func DefaultCopyOptions

func DefaultCopyOptions() *copyOptions

func DefaultGetOptions

func DefaultGetOptions() *getOptions

func DefaultPutOptions

func DefaultPutOptions() *putOptions

func DefaultSignOptions added in v1.0.4

func DefaultSignOptions() *signOptions

func GetReaderLength added in v1.0.5

func GetReaderLength(reader io.ReadSeeker) (int64, error)

func Register added in v1.0.5

func Register(comp Compressor)

Types

type BuildOption

type BuildOption func(c *Container)

func WithAccessKeyID

func WithAccessKeyID(ak string) BuildOption

func WithAccessKeySecret

func WithAccessKeySecret(sk string) BuildOption

func WithBucket

func WithBucket(bucket string) BuildOption

func WithBucketKey

func WithBucketKey(bucketKey string) BuildOption

func WithEndpoint

func WithEndpoint(endpoint string) BuildOption

func WithRegion

func WithRegion(region string) BuildOption

func WithS3ForcePathStyle

func WithS3ForcePathStyle(s3ForcePathStyle bool) BuildOption

func WithS3HttpTimeoutSecs

func WithS3HttpTimeoutSecs(s3HttpTimeoutSecs int64) BuildOption

func WithSSL

func WithSSL(ssl bool) BuildOption

func WithShards

func WithShards(shards []string) BuildOption

func WithStorageType

func WithStorageType(storageType string) BuildOption

type CombinedReadCloser

type CombinedReadCloser struct {
	ReadCloser io.ReadCloser
	Reader     io.Reader
}

CombinedReadCloser combined a ReadCloser and a Readers to a new ReaderCloser which will read from reader and close origin closer

func (CombinedReadCloser) Close

func (combined CombinedReadCloser) Close() error

Close origin ReaderCloser

func (CombinedReadCloser) Read

func (combined CombinedReadCloser) Read(b []byte) (int, error)

type Component

type Component interface {
	GetBucketName(key string) (string, error)
	WithContext(ctx context.Context) Component
	Get(key string, options ...GetOptions) (string, error)
	GetBytes(key string, options ...GetOptions) ([]byte, error)
	GetAsReader(key string, options ...GetOptions) (io.ReadCloser, error)
	GetWithMeta(key string, attributes []string, options ...GetOptions) (io.ReadCloser, map[string]string, error)
	Put(key string, reader io.ReadSeeker, meta map[string]string, options ...PutOptions) error
	Del(key string) error
	DelMulti(keys []string) error
	Head(key string, meta []string) (map[string]string, error)
	ListObject(key string, prefix string, marker string, maxKeys int, delimiter string) ([]string, error)
	SignURL(key string, expired int64, options ...SignOptions) (string, error)
	GetAndDecompress(key string) (string, error)
	GetAndDecompressAsReader(key string) (io.ReadCloser, error)
	CompressAndPut(key string, reader io.ReadSeeker, meta map[string]string, options ...PutOptions) error
	Range(key string, offset int64, length int64) (io.ReadCloser, error)
	Exists(key string) (bool, error)
	Copy(srcKey, dstKey string, options ...CopyOption) error
}

Component interface

type Compressor added in v1.0.5

type Compressor interface {
	Compress(reader io.ReadSeeker) (gzipReader io.ReadSeeker, err error)
	ContentEncoding() string
}

type Container

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

func DefaultContainer

func DefaultContainer() *Container

func Load

func Load(key string) *Container

func (*Container) Build

func (c *Container) Build(options ...BuildOption) Component

type CopyOption

type CopyOption func(options *copyOptions)

func CopyWithAttributes

func CopyWithAttributes(meta []string) CopyOption

CopyWithAttributes specify metadata keys to copy

func CopyWithNewAttributes added in v1.0.5

func CopyWithNewAttributes(meta map[string]string) CopyOption

CopyWithNewAttributes append new attributes(meta) to new object

NOTE: if this option was specified, the metadata(s) of source object would be dropped expect specifying keys to copy using CopyWithAttributes() option.

func CopyWithRawSrcKey

func CopyWithRawSrcKey() CopyOption

type GetOptions

type GetOptions func(options *getOptions)

func EnableCRCValidation

func EnableCRCValidation() GetOptions

func GetWithContentEncoding

func GetWithContentEncoding(contentEncoding string) GetOptions

func GetWithContentType

func GetWithContentType(contentType string) GetOptions

type GzipCompressor added in v1.0.5

type GzipCompressor struct {
}

func (*GzipCompressor) Compress added in v1.0.5

func (g *GzipCompressor) Compress(reader io.ReadSeeker) (gzipReader io.ReadSeeker, err error)

func (*GzipCompressor) ContentEncoding added in v1.0.5

func (g *GzipCompressor) ContentEncoding() string

type HeadGetObjectOutputWrapper

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

type OSS

type OSS struct {
	Bucket *oss.Bucket
	Shards map[string]*oss.Bucket
	// contains filtered or unexported fields
}

func (*OSS) CompressAndPut

func (ossClient *OSS) CompressAndPut(key string, reader io.ReadSeeker, meta map[string]string, options ...PutOptions) error

func (*OSS) Copy

func (ossClient *OSS) Copy(srcKey, dstKey string, options ...CopyOption) error

func (*OSS) Del

func (ossClient *OSS) Del(key string) error

func (*OSS) DelMulti

func (ossClient *OSS) DelMulti(keys []string) error

func (*OSS) Exists

func (ossClient *OSS) Exists(key string) (bool, error)

func (*OSS) Get

func (ossClient *OSS) Get(key string, options ...GetOptions) (string, error)

func (*OSS) GetAndDecompress

func (ossClient *OSS) GetAndDecompress(key string) (string, error)

func (*OSS) GetAndDecompressAsReader

func (ossClient *OSS) GetAndDecompressAsReader(key string) (io.ReadCloser, error)

func (*OSS) GetAsReader

func (ossClient *OSS) GetAsReader(key string, options ...GetOptions) (io.ReadCloser, error)

don't forget to call the close() method of the io.ReadCloser

func (*OSS) GetBucketName

func (ossClient *OSS) GetBucketName(key string) (string, error)

func (*OSS) GetBytes

func (ossClient *OSS) GetBytes(key string, options ...GetOptions) ([]byte, error)

func (*OSS) GetWithMeta

func (ossClient *OSS) GetWithMeta(key string, attributes []string, options ...GetOptions) (io.ReadCloser, map[string]string, error)

don't forget to call the close() method of the io.ReadCloser

func (*OSS) Head

func (ossClient *OSS) Head(key string, attributes []string) (map[string]string, error)

func (*OSS) ListObject

func (ossClient *OSS) ListObject(key string, prefix string, marker string, maxKeys int, delimiter string) ([]string, error)

func (*OSS) Put

func (ossClient *OSS) Put(key string, reader io.ReadSeeker, meta map[string]string, options ...PutOptions) error

func (*OSS) Range

func (ossClient *OSS) Range(key string, offset int64, length int64) (io.ReadCloser, error)

func (*OSS) SignURL

func (ossClient *OSS) SignURL(key string, expired int64, options ...SignOptions) (string, error)

func (*OSS) WithContext

func (ossClient *OSS) WithContext(context.Context) Component

type PutOptions

type PutOptions func(options *putOptions)

func PutWithCacheControl

func PutWithCacheControl(cacheControl string) PutOptions

func PutWithContentDisposition

func PutWithContentDisposition(contentDisposition string) PutOptions

func PutWithContentEncoding

func PutWithContentEncoding(contentEncoding string) PutOptions

func PutWithContentType

func PutWithContentType(contentType string) PutOptions

func PutWithExpireTime

func PutWithExpireTime(expires time.Time) PutOptions

type S3

type S3 struct {
	ShardsBucket map[string]string
	BucketName   string
	Client       *s3.S3
	// contains filtered or unexported fields
}

func (*S3) CompressAndPut

func (a *S3) CompressAndPut(key string, reader io.ReadSeeker, meta map[string]string, options ...PutOptions) error

func (*S3) Copy

func (a *S3) Copy(srcKey, dstKey string, options ...CopyOption) error

func (*S3) Del

func (a *S3) Del(key string) error

func (*S3) DelMulti

func (a *S3) DelMulti(keys []string) error

func (*S3) Exists

func (a *S3) Exists(key string) (bool, error)

func (*S3) Get

func (a *S3) Get(key string, options ...GetOptions) (string, error)

func (*S3) GetAndDecompress

func (a *S3) GetAndDecompress(key string) (string, error)

func (*S3) GetAndDecompressAsReader

func (a *S3) GetAndDecompressAsReader(key string) (io.ReadCloser, error)

func (*S3) GetAsReader

func (a *S3) GetAsReader(key string, options ...GetOptions) (io.ReadCloser, error)

don't forget to call the close() method of the io.ReadCloser

func (*S3) GetBucketName

func (a *S3) GetBucketName(key string) (string, error)

func (*S3) GetBytes

func (a *S3) GetBytes(key string, options ...GetOptions) ([]byte, error)

func (*S3) GetWithMeta

func (a *S3) GetWithMeta(key string, attributes []string, options ...GetOptions) (io.ReadCloser, map[string]string, error)

don't forget to call the close() method of the io.ReadCloser

func (*S3) Head

func (a *S3) Head(key string, attributes []string) (map[string]string, error)

func (*S3) ListObject

func (a *S3) ListObject(key string, prefix string, marker string, maxKeys int, delimiter string) ([]string, error)

func (*S3) Put

func (a *S3) Put(key string, reader io.ReadSeeker, meta map[string]string, options ...PutOptions) error

func (*S3) Range

func (a *S3) Range(key string, offset int64, length int64) (io.ReadCloser, error)

func (*S3) SignURL

func (a *S3) SignURL(key string, expired int64, options ...SignOptions) (string, error)

func (*S3) WithContext

func (a *S3) WithContext(ctx context.Context) Component

type SignOptions added in v1.0.4

type SignOptions func(options *signOptions)

func SignWithProcess added in v1.0.4

func SignWithProcess(process string) SignOptions

Jump to

Keyboard shortcuts

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