storage

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package storage provides an SDK for interacting with blob storage.

Index

Constants

View Source
const MiB = 1 << 20 // 1 MiB

Variables

This section is empty.

Functions

func SplitObjectURI

func SplitObjectURI(uri string) (*string, *string, error)

Types

type BufferReadCloser

type BufferReadCloser struct {
	*bytes.Buffer
}

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 (m *MockStorageClient) ObjectMetadata(ctx context.Context, bucket, name string) (map[string]string, error)

func (*MockStorageClient) ObjectsWithName

func (m *MockStorageClient) ObjectsWithName(ctx context.Context, bucket, filename string) ([]string, error)

func (*MockStorageClient) UploadObject

func (m *MockStorageClient) UploadObject(ctx context.Context, bucket, name string, contents []byte, opts ...UploadOption) error

type Option

type Option func(*Config) *Config

Option is an optional config value for the Google Cloud Storage.

func WithRetryInitialDelay

func WithRetryInitialDelay(initialRetryDelay time.Duration) Option

WithRetryInitialDelay configures the initial delay time before sending a retry for the Google Cloud Storage Client.

func WithRetryMaxDelay

func WithRetryMaxDelay(maxRetryDelay time.Duration) Option

WithRetryMaxDelay configures the maximum delay time before sending a retry for the Google Cloud Storage Client.

func WithRetryMultiplier

func WithRetryMultiplier(retryMultiplier float64) Option

WithRetryMultiplier configures the maximum delay time before sending a retry for the Google Cloud Storage Client.

func WithRetryTimeout

func WithRetryTimeout(retryTimeout time.Duration) Option

WithRetryTimeout configures the maximum allowed timeout duration before sending a retry for the Google Cloud Storage Client.

type Request

type Request struct {
	Name   string
	Params []any
}

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.

Jump to

Keyboard shortcuts

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