storage

package
v0.15.3 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2020 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package storage is an interface over Google Cloud Storage.

Package storage is an interface over file/blob storage.

Index

Constants

View Source
const (
	ContentTypeTextPlain = "text/plain"
	ContentTypeZip       = "application/zip"
)

Variables

View Source
var ErrNotFound = fmt.Errorf("storage object not found")

Functions

This section is empty.

Types

type AWSS3

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

AWSS3 implements the Blob interface and provides the ability write files to AWS S3.

func (*AWSS3) CreateObject

func (s *AWSS3) CreateObject(ctx context.Context, bucket, key string, contents []byte, cacheable bool, contentType string) error

CreateObject creates a new S3 object or overwrites an existing one.

func (*AWSS3) DeleteObject

func (s *AWSS3) DeleteObject(ctx context.Context, bucket, key string) error

DeleteObject deletes a S3 object, returns nil if the object was successfully deleted, or of the object doesn't exist.

func (*AWSS3) GetObject

func (s *AWSS3) GetObject(ctx context.Context, bucket, key string) ([]byte, error)

GetObject returns the contents for the given object. If the object does not exist, it returns ErrNotFound.

type AzureBlobstore

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

AzureBlobstore implements the Blob interface and provides the ability write files to Azure Blob Storage.

func (*AzureBlobstore) CreateObject

func (s *AzureBlobstore) CreateObject(ctx context.Context, container, name string, contents []byte, cacheable bool, contentType string) error

CreateObject creates a new blobstore object or overwrites an existing one.

func (*AzureBlobstore) DeleteObject

func (s *AzureBlobstore) DeleteObject(ctx context.Context, container, name string) error

DeleteObject deletes a blobstore object, returns nil if the object was successfully deleted, or if the object doesn't exist.

func (*AzureBlobstore) GetObject

func (s *AzureBlobstore) GetObject(ctx context.Context, container, name string) ([]byte, error)

GetObject returns the contents for the given object. If the object does not exist, it returns ErrNotFound.

type Blobstore

type Blobstore interface {
	// CreateObject creates or overwrites an object in the storage system.
	// If contentType is blank, the default for the chosen storage implementation is used.
	CreateObject(ctx context.Context, parent, name string, contents []byte, cacheable bool, contentType string) error

	// DeleteObject deletes an object or does nothing if the object doesn't exist.
	DeleteObject(ctx context.Context, parent, bame string) error

	// GetObject fetches the object's contents.
	GetObject(ctx context.Context, parent, name string) ([]byte, error)
}

Blobstore defines the minimum interface for a blob storage system.

func BlobstoreFor

func BlobstoreFor(ctx context.Context, typ BlobstoreType) (Blobstore, error)

BlobstoreFor returns the blob store for the given type, or an error if one does not exist.

func NewAWSS3

func NewAWSS3(ctx context.Context) (Blobstore, error)

NewAWSS3 creates a AWS S3 Service, suitable for use with serverenv.ServerEnv.

func NewAzureBlobstore

func NewAzureBlobstore(ctx context.Context) (Blobstore, error)

NewAzureBlobstore creates a storage client, suitable for use with serverenv.ServerEnv.

func NewFilesystemStorage

func NewFilesystemStorage(ctx context.Context) (Blobstore, error)

NewFilesystemStorage creates a Blobsstore compatible storage for the filesystem.

func NewGoogleCloudStorage

func NewGoogleCloudStorage(ctx context.Context) (Blobstore, error)

NewGoogleCloudStorage creates a Google Cloud Storage Client, suitable for use with serverenv.ServerEnv.

func NewMemory

func NewMemory(_ context.Context) (Blobstore, error)

NewMemory creates a Blobstore that writes data in memory.

func NewNoop

func NewNoop(ctx context.Context) (Blobstore, error)

type BlobstoreType

type BlobstoreType string

BlobstoreType defines a specific blobstore.

const (
	BlobstoreTypeAWSS3              BlobstoreType = "AWS_S3"
	BlobstoreTypeAzureBlobStorage   BlobstoreType = "AZURE_BLOB_STORAGE"
	BlobstoreTypeFilesystem         BlobstoreType = "FILESYSTEM"
	BlobstoreTypeGoogleCloudStorage BlobstoreType = "GOOGLE_CLOUD_STORAGE"
	BlobstoreTypeMemory             BlobstoreType = "MEMORY"
	BlobstoreTypeNoop               BlobstoreType = "NOOP"
)

type Config

type Config struct {
	BlobstoreType BlobstoreType `env:"BLOBSTORE,default=GOOGLE_CLOUD_STORAGE"`
}

Config defines the configuration for a blobstore.

type FilesystemStorage

type FilesystemStorage struct{}

FilesystemStorage implements Blobstore and provides the ability write files to the filesystem.

func (*FilesystemStorage) CreateObject

func (s *FilesystemStorage) CreateObject(ctx context.Context, folder, filename string, contents []byte, cacheable bool, contentType string) error

CreateObject creates a new object on the filesystem or overwrites an existing one. contentType is ignored for this storage implementation.

func (*FilesystemStorage) DeleteObject

func (s *FilesystemStorage) DeleteObject(ctx context.Context, folder, filename string) error

DeleteObject deletes an object from the filesystem. It returns nil if the object was deleted or if the object no longer exists.

func (*FilesystemStorage) GetObject

func (s *FilesystemStorage) GetObject(ctx context.Context, folder, filename string) ([]byte, error)

GetObject returns the contents for the given object. If the object does not exist, it returns ErrNotFound.

type GoogleCloudStorage

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

GoogleCloudStorage implements the Blob interface and provides the ability write files to Google Cloud Storage.

func (*GoogleCloudStorage) CreateObject

func (s *GoogleCloudStorage) CreateObject(ctx context.Context, bucket, objectName string, contents []byte, cacheable bool, contentType string) error

CreateObject creates a new cloud storage object or overwrites an existing one.

func (*GoogleCloudStorage) DeleteObject

func (s *GoogleCloudStorage) DeleteObject(ctx context.Context, bucket, objectName string) error

DeleteObject deletes a cloud storage object, returns nil if the object was successfully deleted, or of the object doesn't exist.

func (*GoogleCloudStorage) GetObject

func (s *GoogleCloudStorage) GetObject(ctx context.Context, bucket, object string) ([]byte, error)

GetObject returns the contents for the given object. If the object does not exist, it returns ErrNotFound.

type Memory

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

Memory implements Blobstore and provides the ability write files to memory.

func (*Memory) CreateObject

func (s *Memory) CreateObject(_ context.Context, folder, filename string, contents []byte, cacheable bool, contentType string) error

CreateObject creates a new object. contentType is ignored in this implementation.

func (*Memory) DeleteObject

func (s *Memory) DeleteObject(_ context.Context, folder, filename string) error

DeleteObject deletes an object. It returns nil if the object was deleted or if the object no longer exists.

func (*Memory) GetObject

func (s *Memory) GetObject(_ context.Context, folder, filename string) ([]byte, error)

GetObject returns the contents for the given object. If the object does not exist, it returns ErrNotFound.

type Noop

type Noop struct{}

Noop is a blobstore that does nothing.

func (*Noop) CreateObject

func (s *Noop) CreateObject(_ context.Context, _, _ string, _ []byte, _ bool, _ string) error

func (*Noop) DeleteObject

func (s *Noop) DeleteObject(_ context.Context, _, _ string) error

func (*Noop) GetObject

func (s *Noop) GetObject(_ context.Context, _, _ string) ([]byte, error)

Jump to

Keyboard shortcuts

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