Documentation ¶
Overview ¶
Package storage provides an SDK for interacting with blob storage.
Index ¶
- Constants
- Variables
- func SplitObjectURI(uri string) (*string, *string, error)
- type BufferReadCloser
- type Config
- type GoogleCloudStorage
- func (s *GoogleCloudStorage) DeleteObject(ctx context.Context, bucket, name string) error
- func (s *GoogleCloudStorage) DownloadObject(ctx context.Context, bucket, name string) (io.ReadCloser, error)
- func (s *GoogleCloudStorage) ObjectMetadata(ctx context.Context, bucket, name string) (map[string]string, error)
- func (s *GoogleCloudStorage) ObjectsWithName(ctx context.Context, bucket, filename string) ([]string, error)
- func (s *GoogleCloudStorage) UploadObject(ctx context.Context, bucket, name string, contents []byte, ...) (merr error)
- type MockStorageClient
- func (m *MockStorageClient) DeleteObject(ctx context.Context, bucket, name string) error
- func (m *MockStorageClient) DownloadObject(ctx context.Context, bucket, name string) (io.ReadCloser, error)
- func (m *MockStorageClient) ObjectMetadata(ctx context.Context, bucket, name string) (map[string]string, error)
- func (m *MockStorageClient) ObjectsWithName(ctx context.Context, bucket, filename string) ([]string, error)
- func (m *MockStorageClient) UploadObject(ctx context.Context, bucket, name string, contents []byte, ...) error
- type Option
- type Request
- type Storage
- type UploadOption
Constants ¶
const MiB = 1 << 20 // 1 MiB
Variables ¶
var (
ErrBucketNotFound = errors.New("bucket not found")
)
Functions ¶
Types ¶
type BufferReadCloser ¶
func (*BufferReadCloser) Close ¶
func (b *BufferReadCloser) Close() error
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config is the configuration for the Google Cloud Storage Client.
type GoogleCloudStorage ¶
type GoogleCloudStorage struct {
// contains filtered or unexported fields
}
GoogleCloudStorage implements the Storage interface for Google Cloud Storage.
func NewGoogleCloudStorage ¶
func NewGoogleCloudStorage(ctx context.Context, opts ...Option) (*GoogleCloudStorage, error)
NewGoogleCloudStorage creates a new GoogleCloudStorage client.
func (*GoogleCloudStorage) DeleteObject ¶
func (s *GoogleCloudStorage) DeleteObject(ctx context.Context, bucket, name string) error
DeleteObject deletes an object from a Google Cloud Storage bucket. If the object does not exist, no error will be returned.
func (*GoogleCloudStorage) DownloadObject ¶
func (s *GoogleCloudStorage) DownloadObject(ctx context.Context, bucket, name string) (io.ReadCloser, error)
DownloadObject downloads an object from a Google Cloud Storage bucket. The caller must call Close on the returned Reader when done reading.
func (*GoogleCloudStorage) ObjectMetadata ¶
func (s *GoogleCloudStorage) ObjectMetadata(ctx context.Context, bucket, name string) (map[string]string, error)
ObjectMetadata gets the metadata for a Google Cloud Storage object.
func (*GoogleCloudStorage) ObjectsWithName ¶
func (s *GoogleCloudStorage) ObjectsWithName(ctx context.Context, bucket, filename string) ([]string, error)
ObjectsWithName returns all files in a bucket with a given file name.
func (*GoogleCloudStorage) UploadObject ¶
func (s *GoogleCloudStorage) UploadObject(ctx context.Context, bucket, name string, contents []byte, opts ...UploadOption) (merr error)
UploadObject uploads an object to a Google Cloud Storage bucket using a set of upload options.
type MockStorageClient ¶
type MockStorageClient struct { Reqs []*Request UploadErr error DownloadData string DownloadErr error Metadata map[string]string MetadataErr error DeleteErr error ListObjectURIs []string ListObjectErr error // contains filtered or unexported fields }
func (*MockStorageClient) DeleteObject ¶
func (m *MockStorageClient) DeleteObject(ctx context.Context, bucket, name string) error
func (*MockStorageClient) DownloadObject ¶
func (m *MockStorageClient) DownloadObject(ctx context.Context, bucket, name string) (io.ReadCloser, error)
func (*MockStorageClient) ObjectMetadata ¶
func (*MockStorageClient) ObjectsWithName ¶
func (*MockStorageClient) UploadObject ¶
func (m *MockStorageClient) UploadObject(ctx context.Context, bucket, name string, contents []byte, opts ...UploadOption) error
type Option ¶
Option is an optional config value for the Google Cloud Storage.
func WithRetryInitialDelay ¶
WithRetryInitialDelay configures the initial delay time before sending a retry for the Google Cloud Storage Client.
func WithRetryMaxDelay ¶
WithRetryMaxDelay configures the maximum delay time before sending a retry for the Google Cloud Storage Client.
func WithRetryMultiplier ¶
WithRetryMultiplier configures the maximum delay time before sending a retry for the Google Cloud Storage Client.
func WithRetryTimeout ¶
WithRetryTimeout configures the maximum allowed timeout duration before sending a retry for the Google Cloud Storage Client.
type Storage ¶
type Storage interface { // UploadObject uploads a blob storage object. UploadObject(ctx context.Context, bucket, name string, contents []byte, opts ...UploadOption) error // DownloadObject downloads a blob storage object. The caller must call Close on the returned Reader when done reading. DownloadObject(ctx context.Context, bucket, name string) (io.ReadCloser, error) // ObjectMetadata gets metadata for a blob storage object. ObjectMetadata(ctx context.Context, bucket, name string) (map[string]string, error) // DeleteObject deletes a blob storage object. DeleteObject(ctx context.Context, bucket, name string) error // ObjectsWithName returns the URIs of files in a given bucket with the filename. ObjectsWithName(ctx context.Context, bucket, filename string) ([]string, error) }
Storage defines the minimum interface for a blob storage system.
type UploadOption ¶
type UploadOption func(*uploadConfig) *uploadConfig
UploadOption is an optional config value for the Google Cloud Storage UploadObject function.
func WithAllowOverwrite ¶
func WithAllowOverwrite(allowOverwrite bool) UploadOption
WithAllowOverwrite sets the overwrite flag to allow overwriting the destination object.
func WithCacheMaxAgeSeconds ¶
func WithCacheMaxAgeSeconds(cacheMaxAgeSeconds int) UploadOption
WithCacheMaxAgeSeconds configures the cache-control header the object upload. Set this value to 0 to prevent caching the file.
func WithChunkSize ¶
func WithChunkSize(chunkSize int) UploadOption
WithChunkSize configures the chunk size for the object upload. Set this value to 0 to send the entire file in a single request.
func WithContentType ¶
func WithContentType(contentType string) UploadOption
WithContentType sets the content type for the object upload.
func WithMetadata ¶
func WithMetadata(metadata map[string]string) UploadOption
WithMetadata sets the metadata for the object upload.