storage

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2021 License: Apache-2.0 Imports: 7 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

func RegisterBlobstore added in v0.22.0

func RegisterBlobstore(name string, fn BlobstoreFunc)

RegisterBlobstore registers a new blobstore with the given name. If a blobstore is already registered with the given name, it panics. Blobstores are usually registered via an init function.

func RegisteredBlobstores added in v0.22.0

func RegisteredBlobstores() []string

RegisteredBlobstores returns the list of the names of the registered blobstores.

Types

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, cfg *Config) (Blobstore, error)

BlobstoreFor returns the blobstore with the given name, or an error if one does not exist.

func NewFilesystemStorage

func NewFilesystemStorage(ctx context.Context, _ *Config) (Blobstore, error)

NewFilesystemStorage creates a Blobsstore compatible storage for the filesystem.

func NewMemory

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

NewMemory creates a Blobstore that writes data in memory.

type BlobstoreFunc added in v0.22.0

type BlobstoreFunc func(context.Context, *Config) (Blobstore, error)

BlobstoreFunc is a func that returns a blobstore or error.

type Config

type Config struct {
	// Type is the type of blobstore.
	Type string `env:"BLOBSTORE, default=MEMORY"`
}

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 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.

Jump to

Keyboard shortcuts

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