Documentation ¶
Index ¶
- Constants
- Variables
- func DefaultConfig() *config
- func DefaultCopyOptions() *copyOptions
- func DefaultGetOptions() *getOptions
- func DefaultPutOptions() *putOptions
- func DefaultSignOptions() *signOptions
- func GetReaderLength(reader io.ReadSeeker) (int64, error)
- func Register(comp Compressor)
- func WrapReader(reader io.ReadSeeker) (io.ReadSeeker, int64, error)
- type BucketConfig
- type BuildOption
- func WithAccessKeyID(ak string) BuildOption
- func WithAccessKeySecret(sk string) BuildOption
- func WithBucket(bucket string) BuildOption
- func WithDebug(debug bool) BuildOption
- func WithEndpoint(endpoint string) BuildOption
- func WithIdleConnTimeout(idleConnTimeout time.Duration) BuildOption
- func WithKeepAlives(enableKeepAlives bool) BuildOption
- func WithMaxIdleConns(maxIdleConns int) BuildOption
- func WithMaxIdleConnsPerHost(maxIdleConnsPerHost int) BuildOption
- func WithRegion(region string) BuildOption
- func WithS3ForcePathStyle(s3ForcePathStyle bool) BuildOption
- func WithS3HttpTimeoutSecs(s3HttpTimeoutSecs int64) BuildOption
- func WithSSL(ssl bool) BuildOption
- func WithShards(shards []string) BuildOption
- func WithStorageType(storageType string) BuildOption
- type Client
- type CombinedReadCloser
- type Component
- func (c *Component) Client(bucket string) Client
- func (c *Component) Copy(ctx context.Context, srcKey, dstKey string, options ...CopyOption) error
- func (c *Component) DefaultClient() Client
- func (c *Component) Del(ctx context.Context, key string) error
- func (c *Component) DelMulti(ctx context.Context, keys []string) error
- func (c *Component) Exists(ctx context.Context, key string) (bool, error)
- func (c *Component) Get(ctx context.Context, key string, options ...GetOptions) (string, error)
- func (c *Component) GetAndDecompress(ctx context.Context, key string) (string, error)
- func (c *Component) GetAndDecompressAsReader(ctx context.Context, key string) (io.ReadCloser, error)
- func (c *Component) GetAsReader(ctx context.Context, key string, options ...GetOptions) (io.ReadCloser, error)
- func (c *Component) GetBucketName(ctx context.Context, key string) (string, error)
- func (c *Component) GetBytes(ctx context.Context, key string, options ...GetOptions) ([]byte, error)
- func (c *Component) GetWithMeta(ctx context.Context, key string, attributes []string, options ...GetOptions) (io.ReadCloser, map[string]string, error)
- func (c *Component) Head(ctx context.Context, key string, attributes []string) (map[string]string, error)
- func (c *Component) ListObject(ctx context.Context, key string, prefix string, marker string, maxKeys int, ...) ([]string, error)
- func (c *Component) Put(ctx context.Context, key string, reader io.ReadSeeker, meta map[string]string, ...) error
- func (c *Component) PutAndCompress(ctx context.Context, key string, reader io.ReadSeeker, meta map[string]string, ...) error
- func (c *Component) Range(ctx context.Context, key string, offset int64, length int64) (io.ReadCloser, error)
- func (c *Component) SignURL(ctx context.Context, key string, expired int64, options ...SignOptions) (string, error)
- type Compressor
- type Container
- type CopyOption
- type GetOptions
- type GzipCompressor
- type HeadGetObjectOutputWrapper
- type LocalFile
- func (l *LocalFile) Copy(ctx context.Context, srcKey, dstKey string, options ...CopyOption) error
- func (l *LocalFile) Del(ctx context.Context, key string) error
- func (l *LocalFile) DelMulti(ctx context.Context, keys []string) error
- func (l *LocalFile) Exists(ctx context.Context, key string) (bool, error)
- func (l *LocalFile) Get(ctx context.Context, key string, options ...GetOptions) (string, error)
- func (l *LocalFile) GetAndDecompress(ctx context.Context, key string) (string, error)
- func (l *LocalFile) GetAndDecompressAsReader(ctx context.Context, key string) (io.ReadCloser, error)
- func (l *LocalFile) GetAsReader(ctx context.Context, key string, options ...GetOptions) (io.ReadCloser, error)
- func (l *LocalFile) GetBucketName(ctx context.Context, key string) (string, error)
- func (l *LocalFile) GetBytes(ctx context.Context, key string, options ...GetOptions) ([]byte, error)
- func (l *LocalFile) GetWithMeta(ctx context.Context, key string, attributes []string, options ...GetOptions) (io.ReadCloser, map[string]string, error)
- func (l *LocalFile) Head(ctx context.Context, key string, attributes []string) (map[string]string, error)
- func (l *LocalFile) ListObject(ctx context.Context, key string, prefix string, marker string, maxKeys int, ...) ([]string, error)
- func (l *LocalFile) Put(ctx context.Context, key string, reader io.ReadSeeker, meta map[string]string, ...) error
- func (l *LocalFile) PutAndCompress(ctx context.Context, key string, reader io.ReadSeeker, meta map[string]string, ...) error
- func (l *LocalFile) Range(ctx context.Context, key string, offset int64, length int64) (io.ReadCloser, error)
- func (l *LocalFile) SignURL(ctx context.Context, key string, expired int64, options ...SignOptions) (string, error)
- type OSS
- func (ossClient *OSS) Copy(ctx context.Context, srcKey, dstKey string, options ...CopyOption) error
- func (ossClient *OSS) Del(ctx context.Context, key string) error
- func (ossClient *OSS) DelMulti(ctx context.Context, keys []string) error
- func (ossClient *OSS) Exists(ctx context.Context, key string) (bool, error)
- func (ossClient *OSS) Get(ctx context.Context, key string, options ...GetOptions) (string, error)
- func (ossClient *OSS) GetAndDecompress(ctx context.Context, key string) (string, error)
- func (ossClient *OSS) GetAndDecompressAsReader(ctx context.Context, key string) (io.ReadCloser, error)
- func (ossClient *OSS) GetAsReader(ctx context.Context, key string, options ...GetOptions) (io.ReadCloser, error)
- func (ossClient *OSS) GetBucketName(ctx context.Context, key string) (string, error)
- func (ossClient *OSS) GetBytes(ctx context.Context, key string, options ...GetOptions) ([]byte, error)
- func (ossClient *OSS) GetWithMeta(ctx context.Context, key string, attributes []string, options ...GetOptions) (io.ReadCloser, map[string]string, error)
- func (ossClient *OSS) Head(ctx context.Context, key string, attributes []string) (map[string]string, error)
- func (ossClient *OSS) ListObject(ctx context.Context, key string, prefix string, marker string, maxKeys int, ...) ([]string, error)
- func (ossClient *OSS) Put(ctx context.Context, key string, reader io.ReadSeeker, meta map[string]string, ...) error
- func (ossClient *OSS) PutAndCompress(ctx context.Context, key string, reader io.ReadSeeker, meta map[string]string, ...) error
- func (ossClient *OSS) Range(ctx context.Context, key string, offset int64, length int64) (io.ReadCloser, error)
- func (ossClient *OSS) SignURL(ctx context.Context, key string, expired int64, options ...SignOptions) (string, error)
- type PutOptions
- type S3
- func (a *S3) Copy(ctx context.Context, srcKey, dstKey string, options ...CopyOption) error
- func (a *S3) Del(ctx context.Context, key string) error
- func (a *S3) DelMulti(ctx context.Context, keys []string) error
- func (a *S3) Exists(ctx context.Context, key string) (bool, error)
- func (a *S3) Get(ctx context.Context, key string, options ...GetOptions) (string, error)
- func (a *S3) GetAndDecompress(ctx context.Context, key string) (string, error)
- func (a *S3) GetAndDecompressAsReader(ctx context.Context, key string) (io.ReadCloser, error)
- func (a *S3) GetAsReader(ctx context.Context, key string, options ...GetOptions) (io.ReadCloser, error)
- func (a *S3) GetBucketName(ctx context.Context, key string) (string, error)
- func (a *S3) GetBytes(ctx context.Context, key string, options ...GetOptions) ([]byte, error)
- func (a *S3) GetWithMeta(ctx context.Context, key string, attributes []string, options ...GetOptions) (io.ReadCloser, map[string]string, error)
- func (a *S3) Head(ctx context.Context, key string, attributes []string) (map[string]string, error)
- func (a *S3) ListObject(ctx context.Context, key string, prefix string, marker string, maxKeys int, ...) ([]string, error)
- func (a *S3) Put(ctx context.Context, key string, reader io.ReadSeeker, meta map[string]string, ...) error
- func (a *S3) PutAndCompress(ctx context.Context, key string, reader io.ReadSeeker, meta map[string]string, ...) error
- func (a *S3) Range(ctx context.Context, key string, offset int64, length int64) (io.ReadCloser, error)
- func (a *S3) SignURL(ctx context.Context, key string, expired int64, options ...SignOptions) (string, error)
- type SignOptions
Constants ¶
const ( StorageTypeOSS = "oss" StorageTypeS3 = "s3" StorageTypeFile = "file" MetaCompressor = "compressor" )
const PackageName = "component.eoss"
Variables ¶
var DefaultGzipCompressor = &GzipCompressor{}
Functions ¶
func DefaultCopyOptions ¶
func DefaultCopyOptions() *copyOptions
func DefaultGetOptions ¶
func DefaultGetOptions() *getOptions
func DefaultPutOptions ¶
func DefaultPutOptions() *putOptions
func DefaultSignOptions ¶
func DefaultSignOptions() *signOptions
func GetReaderLength ¶
func GetReaderLength(reader io.ReadSeeker) (int64, error)
func Register ¶
func Register(comp Compressor)
func WrapReader ¶ added in v0.1.1
func WrapReader(reader io.ReadSeeker) (io.ReadSeeker, int64, error)
Types ¶
type BucketConfig ¶
type BucketConfig struct { // Debug Debug bool // Required, value is one of oss/s3, case insensetive StorageType string // Required AccessKeyID string // Required AccessKeySecret string // Required Endpoint string // Required Bucket name Bucket string // Prefix sets a default global prefix, if not empty, this prefix will automatically be added to all keys by default Prefix 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 // EnableTraceInterceptor enable otel trace (only for s3) EnableTraceInterceptor bool // EnableMetricInterceptor enable prom metrics EnableMetricInterceptor bool // EnableClientTrace EnableClientTrace bool // EnableCompressor EnableCompressor bool // CompressType gzip CompressType string // CompressLimit 大于该值之后才压缩 单位字节 CompressLimit int64 // MaxIdleConns 设置最大空闲连接数 MaxIdleConns int // MaxIdleConnsPerHost 设置长连接个数 MaxIdleConnsPerHost int // EnableKeepAlives 是否开启长连接,默认打开 EnableKeepAlives bool // IdleConnTimeout 设置空闲连接时间,默认90 * time.Second IdleConnTimeout time.Duration }
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 WithDebug ¶
func WithDebug(debug bool) BuildOption
func WithEndpoint ¶
func WithEndpoint(endpoint string) BuildOption
func WithIdleConnTimeout ¶ added in v0.1.1
func WithIdleConnTimeout(idleConnTimeout time.Duration) BuildOption
func WithKeepAlives ¶ added in v0.1.1
func WithKeepAlives(enableKeepAlives bool) BuildOption
func WithMaxIdleConns ¶ added in v0.1.1
func WithMaxIdleConns(maxIdleConns int) BuildOption
func WithMaxIdleConnsPerHost ¶ added in v0.1.1
func WithMaxIdleConnsPerHost(maxIdleConnsPerHost int) 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 Client ¶
type Client interface { GetBucketName(ctx context.Context, key string) (string, error) Get(ctx context.Context, key string, options ...GetOptions) (string, error) GetBytes(ctx context.Context, key string, options ...GetOptions) ([]byte, error) GetAsReader(ctx context.Context, key string, options ...GetOptions) (io.ReadCloser, error) GetWithMeta(ctx context.Context, key string, attributes []string, options ...GetOptions) (io.ReadCloser, map[string]string, error) GetAndDecompress(ctx context.Context, key string) (string, error) GetAndDecompressAsReader(ctx context.Context, key string) (io.ReadCloser, error) Put(ctx context.Context, key string, reader io.ReadSeeker, meta map[string]string, options ...PutOptions) error PutAndCompress(ctx context.Context, key string, reader io.ReadSeeker, meta map[string]string, options ...PutOptions) error Del(ctx context.Context, key string) error DelMulti(ctx context.Context, keys []string) error Head(ctx context.Context, key string, meta []string) (map[string]string, error) ListObject(ctx context.Context, key string, prefix string, marker string, maxKeys int, delimiter string) ([]string, error) SignURL(ctx context.Context, key string, expired int64, options ...SignOptions) (string, error) Range(ctx context.Context, key string, offset int64, length int64) (io.ReadCloser, error) Exists(ctx context.Context, key string) (bool, error) Copy(ctx context.Context, srcKey, dstKey string, options ...CopyOption) error }
Client object storage client interface
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
type Component ¶
type Component struct {
// contains filtered or unexported fields
}
func (*Component) DefaultClient ¶
DefaultClient return default storage client
func (*Component) GetAndDecompress ¶
func (*Component) GetAndDecompressAsReader ¶
func (*Component) GetAsReader ¶
func (c *Component) GetAsReader(ctx context.Context, key string, options ...GetOptions) (io.ReadCloser, error)
GetAsReader don't forget to call the close() method of the io.ReadCloser
func (*Component) GetBucketName ¶
func (*Component) GetWithMeta ¶
func (c *Component) GetWithMeta(ctx context.Context, key string, attributes []string, options ...GetOptions) (io.ReadCloser, map[string]string, error)
GetWithMeta don't forget to call the close() method of the io.ReadCloser
func (*Component) ListObject ¶
func (*Component) Put ¶
func (c *Component) Put(ctx context.Context, key string, reader io.ReadSeeker, meta map[string]string, options ...PutOptions) error
func (*Component) PutAndCompress ¶
func (c *Component) PutAndCompress(ctx context.Context, key string, reader io.ReadSeeker, meta map[string]string, options ...PutOptions) error
type Compressor ¶
type Compressor interface { // Compress(reader io.ReadSeeker) (gzipReader io.ReadSeeker, err error) Compress(reader io.ReadSeeker) (gzipReader io.ReadSeeker, len int64, err error) ContentEncoding() string }
type Container ¶
type Container struct {
// contains filtered or unexported fields
}
func DefaultContainer ¶
func DefaultContainer() *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 ¶
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 ¶
type GzipCompressor struct { }
func (*GzipCompressor) Compress ¶
func (g *GzipCompressor) Compress(reader io.ReadSeeker) (gzipReader io.ReadSeeker, len int64, err error)
func (*GzipCompressor) ContentEncoding ¶
func (g *GzipCompressor) ContentEncoding() string
type HeadGetObjectOutputWrapper ¶
type HeadGetObjectOutputWrapper struct {
// contains filtered or unexported fields
}
type LocalFile ¶ added in v1.0.0
type LocalFile struct {
// contains filtered or unexported fields
}
LocalFile is the implementation based on local files. For desktop APP or test.
func NewLocalFile ¶ added in v1.0.0
func (*LocalFile) GetAndDecompress ¶ added in v1.0.0
func (*LocalFile) GetAndDecompressAsReader ¶ added in v1.0.0
func (*LocalFile) GetAsReader ¶ added in v1.0.0
func (l *LocalFile) GetAsReader(ctx context.Context, key string, options ...GetOptions) (io.ReadCloser, error)
GetAsReader returns reader which you need to close it.
func (*LocalFile) GetBucketName ¶ added in v1.0.0
func (*LocalFile) GetWithMeta ¶ added in v1.0.0
func (*LocalFile) ListObject ¶ added in v1.0.0
func (*LocalFile) Put ¶ added in v1.0.0
func (l *LocalFile) Put(ctx context.Context, key string, reader io.ReadSeeker, meta map[string]string, options ...PutOptions) error
Put override the file It will create two files, one for content, one for meta.
func (*LocalFile) PutAndCompress ¶ added in v1.0.0
func (l *LocalFile) PutAndCompress(ctx context.Context, key string, reader io.ReadSeeker, meta map[string]string, options ...PutOptions) error
type OSS ¶
type OSS struct { Bucket *oss.Bucket Shards map[string]*oss.Bucket // contains filtered or unexported fields }
func (*OSS) GetAndDecompress ¶
func (*OSS) GetAndDecompressAsReader ¶
func (*OSS) GetAsReader ¶
func (ossClient *OSS) GetAsReader(ctx context.Context, key string, options ...GetOptions) (io.ReadCloser, error)
GetAsReader don't forget to call the close() method of the io.ReadCloser
func (*OSS) GetBucketName ¶
func (*OSS) GetWithMeta ¶
func (ossClient *OSS) GetWithMeta(ctx context.Context, key string, attributes []string, options ...GetOptions) (io.ReadCloser, map[string]string, error)
GetWithMeta don't forget to call the close() method of the io.ReadCloser
func (*OSS) ListObject ¶
func (*OSS) Put ¶
func (ossClient *OSS) Put(ctx context.Context, key string, reader io.ReadSeeker, meta map[string]string, options ...PutOptions) error
func (*OSS) PutAndCompress ¶
func (ossClient *OSS) PutAndCompress(ctx context.Context, key string, reader io.ReadSeeker, meta map[string]string, options ...PutOptions) error
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 // contains filtered or unexported fields }
func (*S3) GetAndDecompress ¶
func (*S3) GetAndDecompressAsReader ¶
func (*S3) GetAsReader ¶
func (a *S3) GetAsReader(ctx context.Context, key string, options ...GetOptions) (io.ReadCloser, error)
GetAsReader don't forget to call the close() method of the io.ReadCloser
func (*S3) GetBucketName ¶
func (*S3) GetWithMeta ¶
func (a *S3) GetWithMeta(ctx context.Context, key string, attributes []string, options ...GetOptions) (io.ReadCloser, map[string]string, error)
GetWithMeta don't forget to call the close() method of the io.ReadCloser
func (*S3) ListObject ¶
func (*S3) Put ¶
func (a *S3) Put(ctx context.Context, key string, reader io.ReadSeeker, meta map[string]string, options ...PutOptions) error
func (*S3) PutAndCompress ¶
func (a *S3) PutAndCompress(ctx context.Context, key string, reader io.ReadSeeker, meta map[string]string, options ...PutOptions) error
type SignOptions ¶
type SignOptions func(options *signOptions)
func SignWithProcess ¶
func SignWithProcess(process string) SignOptions