awos

package module
v3.1.7 Latest Latest
Warning

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

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

README

AWOS: 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/shimohq/awos/v3

How to use

import "github.com/shimohq/awos/v3"

awsClient, err := awos.New(&awos.Options{
    // Required, value is one of oss/s3, case insensetive
    StorageType: "string"
    // Required
    AccessKeyID: "string"
    // Required
    AccessKeySecret: "string"
    // Required
    Endpoint: "string"
    // Required
    Bucket: "string"
    // Optional, choose which bucket to use based on the last character of the key,
    // if bucket is 'content', shards is ['abc', 'edf'],
    // then the last character of the key with a/b/c will automatically use the content-abc bucket, and vice versa
    Shards: [2]string{"abc","def"}
    // Only for s3-like
    Region: "string"
    // Only for s3-like, whether to force path style URLs for S3 objects.
    S3ForcePathStyle: false
    // Only for s3-like
    SSL: false
})

Available operations:

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 (
	DefaultHttpTimeout = int64(60)
)

Variables

View Source
var DefaultGzipCompressor = &GzipCompressor{}

Functions

func DefaultConfig added in v3.1.7

func DefaultConfig() *config

DefaultConfig 返回默认配置

func DefaultGetOptions

func DefaultGetOptions() *getOptions

func DefaultPutOptions

func DefaultPutOptions() *putOptions

func DefaultSignOptions added in v3.1.7

func DefaultSignOptions() *signOptions

func GetReaderLength added in v3.1.7

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

func Register added in v3.1.7

func Register(comp Compressor)

Types

type Client

type Client interface {
	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)
}

Client interface

func New

func New(options *Options) (Client, error)

New awos Client instance

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 Compressor added in v3.1.7

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

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 v3.1.7

type GzipCompressor struct {
}

func (*GzipCompressor) Compress added in v3.1.7

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

func (*GzipCompressor) ContentEncoding added in v3.1.7

func (g *GzipCompressor) ContentEncoding() string

type HeadGetObjectOutputWrapper added in v3.1.5

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) 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) GetBytes added in v3.1.2

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)

type Options

type Options struct {
	// Required, value is one of oss/s3, case insensetive
	StorageType string
	// Required
	AccessKeyID string
	// Required
	AccessKeySecret string
	// Required
	Endpoint string
	// Required
	Bucket string
	// Optional, choose which bucket to use based on the last character of the key,
	// if bucket is 'content', shards is ['abc', 'edf'],
	// then the last character of the key with a/b/c will automatically use the content-abc bucket, and vice versa
	Shards []string
	// Only for s3-like
	Region string
	// Only for s3-like, whether to force path style URLs for S3 objects.
	S3ForcePathStyle bool
	// Only for s3-like
	SSL bool
	// Only for s3-like, set http client timeout.
	// oss has default timeout, but s3 default timeout is 0 means no timeout.
	S3HttpTimeoutSecs              int64
	S3HttpTransportMaxConnsPerHost int
	S3HttpTransportIdleConnTimeout time.Duration
	// EnableCompressor
	EnableCompressor bool
	// CompressType gzip
	CompressType string
	// CompressLimit 大于该值之后才压缩 单位字节
	CompressLimit int
}

Options for New method

type PutOptions

type PutOptions func(options *putOptions)

func PutWithCacheControl added in v3.1.3

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 added in v3.1.3

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) 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) GetBytes added in v3.1.2

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)

type SignOptions added in v3.1.7

type SignOptions func(options *signOptions)

func SignWithProcess added in v3.1.7

func SignWithProcess(process string) SignOptions

Jump to

Keyboard shortcuts

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