commonblobgo

package module
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2023 License: Apache-2.0 Imports: 25 Imported by: 2

README

Build Status

common-blob-go

Go library to work with AWS(amazon web services) S3 and GCP(google cloud platform) cloud storage

Usage

Install
go get -u github.com/AccelByte/common-blob-go
Importing
commonblobgo "github.com/AccelByte/common-blob-go"

To create a new storage client, use this function:

storage, err := storage, err := NewCloudStorage(
    ctx,
    isTesting,
    bucketProvider,
    bucketName,
    awsS3Endpoint,
    awsS3Region,
    awsS3AccessKeyID,
    awsS3SecretAccessKey,
    gcpCredentialsJSON,
    gcpStorageEmulatorHost,
)

NewCloudStorage requires such parameters :

  • ctx context.Context : a context that could be cancelled to force-stop the initialization

  • isTesting bool : a flag to switch between external and in-docker-compose dependencies. Used from tests

  • bucketProvider string : provider type. Could be aws or gcp

  • bucketName string : the name of a bucket

  • awsS3Endpoint string : S3 endpoint. Used only from tests(required if bucketProvider==aws and isTesting == true)

  • awsS3Region string : S3 region(required if bucketProvider==aws)

  • awsS3AccessKeyID string : S3 Access key(required if bucketProvider==aws)

  • awsS3SecretAccessKey string : S3 secret key(required if bucketProvider==aws)

  • gcpCredentialsJSON string : GCP JSON credentials(optional if bucketProvider==gcp).

    • If empty - the library will attempt to self-configure from k8s GCP API. The Client(service account) should have the role "Service Account Token Creator"

      Click to expand

      alt text

  • gcpStorageEmulatorHost string : GCP storage host. Used only from tests(required if bucketProvider==gcp and isTesting == true)

To enable cloud storage additional features:

storage, err := storage, err := NewCloudStorageWithOption(
    ctx,
    isTesting,
    bucketProvider,
    bucketName,
    opts,
)

Cloud-specific parameter such as awsRegion, gcpStorageEmulatorHost, etc. has been moved to opts CloudStorageOption.

Supported additional cloud storage feature:

  • opts.AWSEnableS3Accelerate (default: false) : a boolean that indicate S3 bucket use accelerate endpoint. Not available in testing using localstack or using path-style S3 endpoint. Note: make sure to enable transfer accelerate in S3 bucket, please refer to this documentation.
Available methods :
type CloudStorage interface {
	List(ctx context.Context, prefix string) *ListIterator // iterate over all objects in the folder
	ListWithOptions(ctx context.Context, options *ListOptions) *ListIterator // iterate over objects in the folder based on ListOptions criteria 
	Get(ctx context.Context, key string) ([]byte, error) // get the object by a name
	GetReader(ctx context.Context, key string) (io.ReadCloser, error) // get reader to operate with io.ReadCloser
	Delete(ctx context.Context, key string) error // delete the object by a name
	CreateBucket(ctx context.Context, bucketPrefix string, expirationTimeDays int64) error // create a bucket. Used only from tests
	Close() // close connection
	GetSignedURL(ctx context.Context, key string, expiry time.Duration) (string, error) // create signed URL
	Write(ctx context.Context, key string, body []byte, contentType *string) error // write the object a file-name
	GetWriter(ctx context.Context, key string) (io.WriteCloser, error) // get writer to operate with io.WriteCloser
	Attributes(ctx context.Context, key string) (*Attributes, error) // get object attributes
	Exists(ctx context.Context, key string) (bool, error) // check object existence
}
Examples:
List(ctx context.Context, prefix string) *ListIterator
    list := storage.List(ctx, bucketPrefix)

    for {
        item, err := list.Next(ctx)
        if err == io.EOF {
            break // no more object
        }

        // ...

        if item.Key == fileName {
            fileFound = true
        }
    }
ListWithOptions(ctx context.Context, options *ListOptions) *ListIterator
    list := storage.CloudStorage.ListWithOptions(parentCtx, &commonblobgo.ListOptions{
        Prefix:    bucketPrefix,

        // An empty delimiter means that the bucket is treated as a single flat namespace.
        //
        // A non-empty delimiter means that any result with the delimiter in its key after Prefix is stripped will be returned with ListObject.IsDir = true,
        // ListObject.Key truncated after the delimiter. These results represent "directories"
        Delimiter: "/", 
    })

    var directories []string
    for {
        item, err := list.Next(ctx)
        if err == io.EOF {
            break // no more object
        }

        // ...

        if item.IsDir {
            directories = append(directories, item.Key)
        }
    }
Get(ctx context.Context, key string) ([]byte, error)
    storedBody, err := storage.Get(ctx, fileName)
    if err != nil { 
        return nil, err
    }   

    fmt.Println(string(storedBody))
GetReader(ctx context.Context, key string) (io.ReadCloser, error)
    reader, err := storage.GetReader(ctx, fileName)
    if err != nil { 
        return nil, err
    }
    defer reader.Close() // Important to prevent memory leaks

    storedBody, err := ioutil.ReadAll(reader)
    fmt.Println(string(storedBody))
GetRangeReader(ctx context.Context, key string, offset int64, length int64) (io.ReadCloser, error)
    reader, err := storage.GetRangeReader(ctx, fileName, offset, length)
    if err != nil { 
        return nil, err
    }
    defer reader.Close() // Important to prevent memory leaks

    storedBody, err := ioutil.ReadAll(reader)
    fmt.Println(string(storedBody))
Delete(ctx context.Context, key string) error
    err = storage.Delete(ctx, fileName)
    if err != nil { 
        return nil, err
    }   
CreateBucket(ctx context.Context, bucketPrefix string, expirationTimeDays int64) error
    err = storage.CreateBucket(ctx, bucketPrefix, 1)
    if err != nil { 
        return nil, err
    }   
Close()
    storage, err := storage, err := NewCloudStorage(
        ctx,
        isTesting,
        bucketProvider,
        bucketName,
        awsS3Endpoint,
        awsS3Region,
        awsS3AccessKeyID,
        awsS3SecretAccessKey,
        gcpCredentialsJSON,
        gcpStorageEmulatorHost,
    )

    defer storage.Close()
GetSignedURL(ctx context.Context, key string, expiry time.Duration) (string, error)
    url, err := storage.GetSignedURL(ctx, fileName, time.Hour)
    if err != nil { 
        return nil, err
    }   

    fmt.Println(url)
Write(ctx context.Context, key string, body []byte, contentType *string) error
    err := storage.Write(ctx, fileName, bodyBytes, nil)
    if err != nil { 
        return nil, err
    }   
GetWriter(ctx context.Context, key string) (io.WriteCloser, error)
	body := []byte(`{"key": "value", "key2": "value2"}`)

	writer, err := storage.GetWriter(ctx, fileName)
    if err != nil { 
        return nil, err
    }   

	_, err = writer.Write(body[:10])
    if err != nil { 
        return nil, err
    }   

	_, err = writer.Write(body[10:20])
    if err != nil { 
        return nil, err
    }   

	_, err = writer.Write(body[20:])
    if err != nil { 
        return nil, err
    }   

	err = writer.Close()
    if err != nil { 
        return nil, err
    }   
Attributes(ctx context.Context, key string) (*Attributes, error)
    attrs, err := storage.Attributes(ctx, fileName)
    if err != nil { 
        return nil, err
    }   
    
    fmt.Println(attrs.Size)
Exists(ctx context.Context, key string) (bool, error)
    isExists, err := storage.Exists(ctx, fileName)
    if err != nil { 
        return nil, err
    }   

    if isExists {
        fmt.Println("found")
    }
License
Copyright © 2020, AccelByte Inc. Released under the Apache License, Version 2.0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AWSCloudStorage

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

func (*AWSCloudStorage) Attributes

func (ts *AWSCloudStorage) Attributes(
	ctx context.Context,
	key string,
) (*Attributes, error)

func (*AWSCloudStorage) Close

func (ts *AWSCloudStorage) Close()

func (*AWSCloudStorage) CreateBucket

func (ts *AWSCloudStorage) CreateBucket(
	ctx context.Context,
	bucketPrefix string,
	expirationTimeDays int64,
) error

func (*AWSCloudStorage) Delete

func (ts *AWSCloudStorage) Delete(
	ctx context.Context,
	key string,
) error

func (*AWSCloudStorage) Exists added in v0.7.0

func (ts *AWSCloudStorage) Exists(
	ctx context.Context,
	key string,
) (bool, error)

func (*AWSCloudStorage) Get

func (ts *AWSCloudStorage) Get(
	ctx context.Context,
	key string,
) ([]byte, error)

func (*AWSCloudStorage) GetRangeReader added in v0.1.0

func (ts *AWSCloudStorage) GetRangeReader(
	ctx context.Context,
	key string,
	offset,
	length int64,
) (io.ReadCloser, error)

func (*AWSCloudStorage) GetReader added in v0.0.3

func (ts *AWSCloudStorage) GetReader(
	ctx context.Context,
	key string,
) (io.ReadCloser, error)

func (*AWSCloudStorage) GetSignedURL

func (ts *AWSCloudStorage) GetSignedURL(
	ctx context.Context,
	key string,
	opts *SignedURLOption,
) (string, error)

func (*AWSCloudStorage) GetWriter added in v0.0.3

func (ts *AWSCloudStorage) GetWriter(
	ctx context.Context,
	key string,
) (io.WriteCloser, error)

func (*AWSCloudStorage) List

func (ts *AWSCloudStorage) List(
	ctx context.Context,
	prefix string,
) *ListIterator

func (*AWSCloudStorage) ListWithOptions added in v0.6.0

func (ts *AWSCloudStorage) ListWithOptions(
	ctx context.Context,
	listOptions *ListOptions,
) *ListIterator

func (*AWSCloudStorage) Write

func (ts *AWSCloudStorage) Write(
	ctx context.Context,
	key string,
	body []byte,
	contentType *string,
) error

type AWSTestCloudStorage

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

func (*AWSTestCloudStorage) Attributes

func (ts *AWSTestCloudStorage) Attributes(
	ctx context.Context,
	key string,
) (*Attributes, error)

func (*AWSTestCloudStorage) Close

func (ts *AWSTestCloudStorage) Close()

func (*AWSTestCloudStorage) CreateBucket

func (ts *AWSTestCloudStorage) CreateBucket(
	ctx context.Context,
	bucketPrefix string,
	expirationTimeDays int64,
) error

func (*AWSTestCloudStorage) Delete

func (ts *AWSTestCloudStorage) Delete(
	ctx context.Context,
	key string,
) error

func (*AWSTestCloudStorage) Exists added in v0.7.0

func (ts *AWSTestCloudStorage) Exists(
	ctx context.Context,
	key string,
) (bool, error)

func (*AWSTestCloudStorage) Get

func (ts *AWSTestCloudStorage) Get(
	ctx context.Context,
	key string,
) ([]byte, error)

func (*AWSTestCloudStorage) GetRangeReader added in v0.1.0

func (ts *AWSTestCloudStorage) GetRangeReader(
	ctx context.Context,
	key string,
	offset,
	length int64,
) (io.ReadCloser, error)

func (*AWSTestCloudStorage) GetReader added in v0.0.3

func (ts *AWSTestCloudStorage) GetReader(
	ctx context.Context,
	key string,
) (io.ReadCloser, error)

func (*AWSTestCloudStorage) GetSignedURL

func (ts *AWSTestCloudStorage) GetSignedURL(
	ctx context.Context,
	key string,
	opts *SignedURLOption,
) (string, error)

func (*AWSTestCloudStorage) GetWriter added in v0.0.3

func (ts *AWSTestCloudStorage) GetWriter(
	ctx context.Context,
	key string,
) (io.WriteCloser, error)

func (*AWSTestCloudStorage) List

func (ts *AWSTestCloudStorage) List(
	ctx context.Context,
	prefix string,
) *ListIterator

func (*AWSTestCloudStorage) ListWithOptions added in v0.6.0

func (ts *AWSTestCloudStorage) ListWithOptions(
	ctx context.Context,
	listOptions *ListOptions,
) *ListIterator

func (*AWSTestCloudStorage) Write

func (ts *AWSTestCloudStorage) Write(
	ctx context.Context,
	key string,
	body []byte,
	contentType *string,
) error

type Attributes

type Attributes struct {
	// CacheControl specifies caching attributes that services may use
	// when serving the blob.
	// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
	CacheControl string
	// ContentDisposition specifies whether the blob content is expected to be
	// displayed inline or as an attachment.
	// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition
	ContentDisposition string
	// ContentEncoding specifies the encoding used for the blob's content, if any.
	// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding
	ContentEncoding string
	// ContentLanguage specifies the language used in the blob's content, if any.
	// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Language
	ContentLanguage string
	// ContentType is the MIME type of the blob. It will not be empty.
	// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type
	ContentType string
	// Metadata holds key/value pairs associated with the blob.
	// Keys are guaranteed to be in lowercase, even if the backend service
	// has case-sensitive keys (although note that Metadata written via
	// this package will always be lowercased). If there are duplicate
	// case-insensitive keys (e.g., "foo" and "FOO"), only one value
	// will be kept, and it is undefined which one.
	Metadata map[string]string
	// ModTime is the time the blob was last modified.
	ModTime time.Time
	// Size is the size of the blob's content in bytes.
	Size int64
	// MD5 is an MD5 hash of the blob contents or nil if not available.
	MD5 []byte
}

Attributes contains attributes about a blob.

type CloudStorage

type CloudStorage interface {
	List(ctx context.Context, prefix string) *ListIterator
	ListWithOptions(ctx context.Context, options *ListOptions) *ListIterator
	Get(ctx context.Context, key string) ([]byte, error)
	Delete(ctx context.Context, key string) error
	CreateBucket(ctx context.Context, bucketPrefix string, expirationTimeDays int64) error
	Close()
	GetSignedURL(ctx context.Context, key string, opts *SignedURLOption) (string, error)
	Write(ctx context.Context, key string, body []byte, contentType *string) error
	Attributes(ctx context.Context, key string) (*Attributes, error)
	GetReader(ctx context.Context, key string) (io.ReadCloser, error)
	GetRangeReader(ctx context.Context, key string, offset, length int64) (io.ReadCloser, error)
	GetWriter(ctx context.Context, key string) (io.WriteCloser, error)
	Exists(ctx context.Context, key string) (bool, error)
}

func NewCloudStorage

func NewCloudStorage(
	ctx context.Context,
	isTesting bool,
	bucketProvider string,
	bucketName string,

	awsS3Endpoint string,
	awsS3Region string,
	awsS3AccessKeyID string,
	awsS3SecretAccessKey string,

	gcpCredentialsJSON string,
	gcpStorageEmulatorHost string,
) (CloudStorage, error)

func NewCloudStorageWithOption added in v0.4.0

func NewCloudStorageWithOption(ctx context.Context, isTesting bool, bucketProvider, bucketName string, cloudStorageOpts CloudStorageOption) (CloudStorage, error)

type CloudStorageOption added in v0.4.0

type CloudStorageOption struct {
	AWSS3Endpoint         string
	AWSS3Region           string
	AWSS3AccessKeyID      string
	AWSS3SecretAccessKey  string
	AWSEnableS3Accelerate bool

	// AWSTokenDuration is the duration of the STS token will be valid. If not set, the assumed role will use default
	// expiry duration.  See https://docs.aws.amazon.com/sdk-for-go/api/service/sts/#STS.AssumeRoleWithWebIdentity
	// for more information.
	//
	// Important notes: the value MUST BE no more than the maximum session duration of the AWS role.
	// If unset, it will use the default maximum session duration of the AWS role.
	AWSTokenDuration time.Duration

	// The amount of time the token will be refreshed before they expire. It's important to refresh token before they
	// expire to reduce risk of using expired token. The refresh token is not done periodically in the background,
	// instead will be triggered by any operation using AWS session.
	// If unset, will default to no expiry window.
	AWSTokenExpiryWindow time.Duration

	GCPCredentialsJSON     string
	GCPStorageEmulatorHost string
}

type ExplicitGCPCloudStorage added in v0.0.5

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

func (*ExplicitGCPCloudStorage) Attributes added in v0.0.5

func (ts *ExplicitGCPCloudStorage) Attributes(
	ctx context.Context,
	key string,
) (*Attributes, error)

func (*ExplicitGCPCloudStorage) Close added in v0.0.5

func (ts *ExplicitGCPCloudStorage) Close()

func (*ExplicitGCPCloudStorage) CreateBucket added in v0.0.5

func (ts *ExplicitGCPCloudStorage) CreateBucket(
	ctx context.Context,
	bucketPrefix string,
	expirationTimeDays int64,
) error

func (*ExplicitGCPCloudStorage) Delete added in v0.0.5

func (ts *ExplicitGCPCloudStorage) Delete(
	ctx context.Context,
	key string,
) error

func (*ExplicitGCPCloudStorage) Exists added in v0.7.0

func (ts *ExplicitGCPCloudStorage) Exists(
	ctx context.Context,
	key string,
) (bool, error)

func (*ExplicitGCPCloudStorage) Get added in v0.0.5

func (ts *ExplicitGCPCloudStorage) Get(
	ctx context.Context,
	key string,
) ([]byte, error)

func (*ExplicitGCPCloudStorage) GetRangeReader added in v0.1.0

func (ts *ExplicitGCPCloudStorage) GetRangeReader(
	ctx context.Context,
	key string,
	offset,
	length int64,
) (io.ReadCloser, error)

func (*ExplicitGCPCloudStorage) GetReader added in v0.0.5

func (ts *ExplicitGCPCloudStorage) GetReader(
	ctx context.Context,
	key string,
) (io.ReadCloser, error)

func (*ExplicitGCPCloudStorage) GetSignedURL added in v0.0.5

func (ts *ExplicitGCPCloudStorage) GetSignedURL(
	ctx context.Context,
	key string,
	opts *SignedURLOption,
) (string, error)

func (*ExplicitGCPCloudStorage) GetWriter added in v0.0.5

func (ts *ExplicitGCPCloudStorage) GetWriter(
	ctx context.Context,
	key string,
) (io.WriteCloser, error)

func (*ExplicitGCPCloudStorage) List added in v0.0.5

func (ts *ExplicitGCPCloudStorage) List(
	ctx context.Context,
	prefix string,
) *ListIterator

func (*ExplicitGCPCloudStorage) ListWithOptions added in v0.6.0

func (ts *ExplicitGCPCloudStorage) ListWithOptions(
	ctx context.Context,
	listOptions *ListOptions,
) *ListIterator

func (*ExplicitGCPCloudStorage) Write added in v0.0.5

func (ts *ExplicitGCPCloudStorage) Write(
	ctx context.Context,
	key string,
	body []byte,
	contentType *string,
) error

type GCPTestCloudStorage

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

func (*GCPTestCloudStorage) Attributes

func (ts *GCPTestCloudStorage) Attributes(
	ctx context.Context,
	key string,
) (*Attributes, error)

func (*GCPTestCloudStorage) Close

func (ts *GCPTestCloudStorage) Close()

func (*GCPTestCloudStorage) CreateBucket

func (ts *GCPTestCloudStorage) CreateBucket(
	ctx context.Context,
	bucketPrefix string,
	expirationTimeDays int64,
) error

func (*GCPTestCloudStorage) Delete

func (ts *GCPTestCloudStorage) Delete(
	ctx context.Context,
	key string,
) error

func (*GCPTestCloudStorage) Exists added in v0.7.0

func (ts *GCPTestCloudStorage) Exists(
	ctx context.Context,
	key string,
) (bool, error)

func (*GCPTestCloudStorage) Get

func (ts *GCPTestCloudStorage) Get(
	ctx context.Context,
	key string,
) ([]byte, error)

func (*GCPTestCloudStorage) GetRangeReader added in v0.1.0

func (ts *GCPTestCloudStorage) GetRangeReader(
	ctx context.Context,
	key string,
	offset,
	length int64,
) (io.ReadCloser, error)

func (*GCPTestCloudStorage) GetReader added in v0.0.3

func (ts *GCPTestCloudStorage) GetReader(
	ctx context.Context,
	key string,
) (io.ReadCloser, error)

func (*GCPTestCloudStorage) GetSignedURL

func (ts *GCPTestCloudStorage) GetSignedURL(
	ctx context.Context,
	key string,
	opts *SignedURLOption,
) (string, error)

func (*GCPTestCloudStorage) GetWriter added in v0.0.3

func (ts *GCPTestCloudStorage) GetWriter(
	ctx context.Context,
	key string,
) (io.WriteCloser, error)

func (*GCPTestCloudStorage) List

func (ts *GCPTestCloudStorage) List(
	ctx context.Context,
	prefix string,
) *ListIterator

func (*GCPTestCloudStorage) ListWithOptions added in v0.6.0

func (ts *GCPTestCloudStorage) ListWithOptions(
	ctx context.Context,
	listOptions *ListOptions,
) *ListIterator

func (*GCPTestCloudStorage) Write

func (ts *GCPTestCloudStorage) Write(
	ctx context.Context,
	key string,
	body []byte,
	contentType *string,
) error

type ImplicitGCPCloudStorage added in v0.0.5

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

func (*ImplicitGCPCloudStorage) Attributes added in v0.0.5

func (ts *ImplicitGCPCloudStorage) Attributes(
	ctx context.Context,
	key string,
) (*Attributes, error)

func (*ImplicitGCPCloudStorage) Close added in v0.0.5

func (ts *ImplicitGCPCloudStorage) Close()

func (*ImplicitGCPCloudStorage) CreateBucket added in v0.0.5

func (ts *ImplicitGCPCloudStorage) CreateBucket(
	ctx context.Context,
	bucketPrefix string,
	expirationTimeDays int64,
) error

func (*ImplicitGCPCloudStorage) Delete added in v0.0.5

func (ts *ImplicitGCPCloudStorage) Delete(
	ctx context.Context,
	key string,
) error

func (*ImplicitGCPCloudStorage) Exists added in v0.7.0

func (ts *ImplicitGCPCloudStorage) Exists(
	ctx context.Context,
	key string,
) (bool, error)

func (*ImplicitGCPCloudStorage) Get added in v0.0.5

func (ts *ImplicitGCPCloudStorage) Get(
	ctx context.Context,
	key string,
) ([]byte, error)

func (*ImplicitGCPCloudStorage) GetRangeReader added in v0.1.0

func (ts *ImplicitGCPCloudStorage) GetRangeReader(
	ctx context.Context,
	key string,
	offset,
	length int64,
) (io.ReadCloser, error)

func (*ImplicitGCPCloudStorage) GetReader added in v0.0.5

func (ts *ImplicitGCPCloudStorage) GetReader(
	ctx context.Context,
	key string,
) (io.ReadCloser, error)

func (*ImplicitGCPCloudStorage) GetSignedURL added in v0.0.5

func (ts *ImplicitGCPCloudStorage) GetSignedURL(
	ctx context.Context,
	key string,
	opts *SignedURLOption,
) (string, error)

func (*ImplicitGCPCloudStorage) GetWriter added in v0.0.5

func (ts *ImplicitGCPCloudStorage) GetWriter(
	ctx context.Context,
	key string,
) (io.WriteCloser, error)

func (*ImplicitGCPCloudStorage) List added in v0.0.5

func (ts *ImplicitGCPCloudStorage) List(
	ctx context.Context,
	prefix string,
) *ListIterator

func (*ImplicitGCPCloudStorage) ListWithOptions added in v0.6.0

func (ts *ImplicitGCPCloudStorage) ListWithOptions(
	ctx context.Context,
	listOptions *ListOptions,
) *ListIterator

func (*ImplicitGCPCloudStorage) Write added in v0.0.5

func (ts *ImplicitGCPCloudStorage) Write(
	ctx context.Context,
	key string,
	body []byte,
	contentType *string,
) error

type ListIterator

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

ListIterator iterates over List results.

func (*ListIterator) Next

func (i *ListIterator) Next(ctx context.Context) (*ListObject, error)

type ListObject

type ListObject struct {
	// Key is the key for this blob.
	Key string
	// ModTime is the time the blob was last modified.
	ModTime time.Time
	// Size is the size of the blob's content in bytes.
	Size int64
	// MD5 is an MD5 hash of the blob contents or nil if not available.
	MD5 []byte
	// IsDir indicates that this result represents a "directory" in the
	// hierarchical namespace, ending in ListOptions.Delimiter. Key can be
	// passed as ListOptions.Prefix to list items in the "directory".
	// Fields other than Key and IsDir will not be set if IsDir is true.
	IsDir bool
}

ListObject represents a single blob returned from List.

type ListOptions added in v0.6.0

type ListOptions struct {
	// Prefix indicates that only blobs with a key starting with this prefix
	// should be returned.
	Prefix string
	// Delimiter sets the delimiter used to define a hierarchical namespace,
	// like a filesystem with "directories". It is highly recommended that you
	// use "" or "/" as the Delimiter. Other values should work through this API,
	// but service UIs generally assume "/".
	//
	// An empty delimiter means that the bucket is treated as a single flat
	// namespace.
	//
	// A non-empty delimiter means that any result with the delimiter in its key
	// after Prefix is stripped will be returned with ListObject.IsDir = true,
	// ListObject.Key truncated after the delimiter, and zero values for other
	// ListObject fields. These results represent "directories". Multiple results
	// in a "directory" are returned as a single result.
	Delimiter string
}

ListOptions sets options for listing blobs.

type SignedURLOption added in v0.2.1

type SignedURLOption struct {
	Method                   string
	Expiry                   time.Duration
	ContentType              string
	EnforceAbsentContentType bool
}

Jump to

Keyboard shortcuts

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