Documentation ¶
Index ¶
- Variables
- type Document
- func (doc Document) Replace(ctx context.Context, r io.Reader, storage Storage) (Document, error)
- func (doc Document) Upload(ctx context.Context, r io.Reader, storage Storage) (Document, error)
- func (doc Document) WithTag(tags ...string) Document
- func (doc Document) WithoutTag(tags ...string) Document
- type File
- func (f File) Delete(ctx context.Context, storage Storage) error
- func (f File) Download(ctx context.Context, storage Storage) ([]byte, error)
- func (f File) HasTag(tags ...string) bool
- func (f File) Replace(ctx context.Context, r io.Reader, storage Storage) (File, error)
- func (f File) Same(other File) bool
- func (f File) Upload(ctx context.Context, r io.Reader, storage Storage) (File, error)
- func (f File) WithTag(tags ...string) File
- func (f File) WithoutTag(tags ...string) File
- type Image
- func (img Image) Download(ctx context.Context, storage Storage) (image.Image, string, error)
- func (img Image) Replace(ctx context.Context, r io.Reader, storage Storage) (Image, error)
- func (img Image) Upload(ctx context.Context, r io.Reader, storage Storage) (Image, error)
- func (img Image) WithTag(tags ...string) Image
- func (img Image) WithoutTag(tags ...string) Image
- type Storage
- type StorageDisk
- type StorageOption
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUnconfiguredDisk is returned when trying to get a StorageDisk that // isn't configured. ErrUnconfiguredDisk = errors.New("unconfigured disk") // ErrFileNotFound is returned when a file cannot be found in a Storage. ErrFileNotFound = errors.New("file not found") // ErrUploadFailed is returned when an upload of a file fails. ErrUploadFailed = errors.New("upload failed") // ErrEmptyName is returned when providing an empty string as a name. // Whitespce-only strings count as empty. ErrEmptyName = errors.New("empty name") )
Functions ¶
This section is empty.
Types ¶
type Document ¶
type Document struct {
File
}
Document is an arbitrary storage file.
func NewDocument ¶
NewDocument returns a Document with the given data.
func (Document) Replace ¶
Replace replaces the document in Storage with the document in r and returns the updated Document.
func (Document) Upload ¶
Upload uploads the document to storage and returns the Document with updated Filesize.
func (Document) WithoutTag ¶
WithoutTags removes the given tags and returns the updated Document.
type File ¶
type File struct { Name string `json:"name"` Disk string `json:"disk"` Path string `json:"path"` Filesize int `json:"filesize"` Tags []string `json:"tags"` }
File is a file that is stored in a storage backend.
func NewFile ¶
NewFile returns a File with the specified data. NewFile ensures that returned File f has a non-nil f.Tags slice.
func (File) HasTag ¶
HasTag returns whether the File has the given tags. HasTag returns true if the File has all provided tags or if len(tags) == 0.
func (File) Replace ¶
Replace replaces the file in storage with the contents in r and returns the updated File.
func (File) WithoutTag ¶
WithoutTags removes the given tags and returns the updated File.
type Image ¶
Image is storage image.
func (Image) Download ¶
Download downloads the image from the provided Storage and returns the decoded Image and its format. If you want to download the image without decoding it into an image.Image, use img.File.Download instead.
func (Image) Replace ¶
Replace replaces the image in Storage with the image in r and returns the updated Image.
func (Image) Upload ¶
Upload uploads the image to storage and returns the Image with updated Filesize, Width and Height.
func (Image) WithoutTag ¶
WithoutTags removes the given tags and returns the updated Image.
type Storage ¶
type Storage interface { // Disk returns the StorageDisk that was configured with the given name or // ErrUnconfiguredDisk if the disk wasn't configured. Disk(string) (StorageDisk, error) }
Storage is a storage for files.
func GoDriveStorage ¶
GoDriveStorage returns a Storage that uses `godrive` as the storage engine.
func NewStorage ¶
func NewStorage(opts ...StorageOption) Storage
NewStorage returns a Storage, configured by opts.
type StorageDisk ¶
type StorageDisk interface { // Put uploads a file to the specified storage path or ErrFileNotFound if // the file does not exist. Put(context.Context, string, []byte) error // Get returns the contents of the file at the specified path or // ErrFileNotFound if the file does not exist. Get(context.Context, string) ([]byte, error) // Delete deletes the file at the specified path. Delete returns no error // if the specified file does not exist. Delete(context.Context, string) error }
StorageDisk is a disk of a Storage.
type StorageOption ¶
type StorageOption func(*storage)
StorageOption is an option for creating a Storage.
func ConfigureDisk ¶
func ConfigureDisk(name string, disk StorageDisk) StorageOption
ConfigureDisk returns a StorageOption that configures a StorageDisk under the provided name.
Directories ¶
Path | Synopsis |
---|---|
mock_document
Package mock_document is a generated GoMock package.
|
Package mock_document is a generated GoMock package. |
gallery/mock_gallery
Package mock_gallery is a generated GoMock package.
|
Package mock_gallery is a generated GoMock package. |
mock_image
Package mock_image is a generated GoMock package.
|
Package mock_image is a generated GoMock package. |
Package mock_media is a generated GoMock package.
|
Package mock_media is a generated GoMock package. |