Documentation ¶
Overview ¶
Package storage is an interface over Google Cloud Storage.
Package storage is an interface over file/blob storage.
Index ¶
- Constants
- Variables
- func RegisterBlobstore(name string, fn BlobstoreFunc)
- func RegisteredBlobstores() []string
- type Blobstore
- type BlobstoreFunc
- type Config
- type FilesystemStorage
- func (s *FilesystemStorage) CreateObject(ctx context.Context, folder, filename string, contents []byte, cacheable bool, ...) error
- func (s *FilesystemStorage) DeleteObject(ctx context.Context, folder, filename string) error
- func (s *FilesystemStorage) GetObject(ctx context.Context, folder, filename string) ([]byte, error)
- type Memory
Constants ¶
const ( ContentTypeTextPlain = "text/plain" ContentTypeZip = "application/zip" )
Variables ¶
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 ¶
BlobstoreFor returns the blobstore with the given name, or an error if one does not exist.
func NewFilesystemStorage ¶
NewFilesystemStorage creates a Blobsstore compatible storage for the filesystem.
type BlobstoreFunc ¶ added in v0.22.0
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.
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 ¶
DeleteObject deletes an object. It returns nil if the object was deleted or if the object no longer exists.