Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrMimeType is returned by validate when a mimetype is // not permitted. ErrMimeType = errors.New("mimetype is not permitted") // ErrFileTooBig is returned by validate when a file is to // big to be uploaded. ErrFileTooBig = errors.New("file size to big to be uploaded") )
Functions ¶
This section is empty.
Types ¶
type ExistsFunc ¶
ExistsFunc is used by the uploader to determine if a media item exists in the library.
type Imager ¶
type Imager interface { Decode() (image.Image, error) Save(image image.Image, path string, comp int) error }
Imager describes the methods for decoding and saving different image types such as PNG's and JPG's
type JPG ¶
JPG implementation of an Imager.
type Library ¶
type Library interface { Upload(file *multipart.FileHeader) (domain.Media, error) Serve(media domain.Media, path string, acceptWebP bool) ([]byte, domain.Mime, error) Validate(file *multipart.FileHeader) error Delete(item domain.Media) }
Library defines methods for media items to save, validate and delete from the local file system.
type PNG ¶
PNG implementation of an Imager.
type Resizer ¶
type Resizer interface {
Resize(imager Imager, dest string, media domain.MediaSize, comp int) error
}
Resizer describes the method for resizing images for the library.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service
Defines the service for uploading, validating, deleting and serving rich media from the Verbis media library.
func (*Service) Delete ¶
Delete
Satisfies the Library to remove possible media item combinations from the file system, if the file does not exist (user moved) it will be skipped.
Logs errors.INTERNAL if the file could not be deleted.
func (*Service) Serve ¶
func (s *Service) Serve(media domain.Media, path string, acceptWebP bool) ([]byte, domain.Mime, error)
Serve
Serve is responsible for serving the correct data to the front end. Returns errors.NOTFOUND if the media item was not found.
func (*Service) Upload ¶
Upload
Satisfies the Library to upload a media item to the library. Media items will be opened and saved to the local file system. Images are resized and saved in correspondence to the options. This function expects that validate has been called before it is run.
Returns errors.INTERNAL on any eventuality the file could not be opened. Returns errors.INVALID if the mimetype could not be found.
func (*Service) Validate ¶
func (s *Service) Validate(file *multipart.FileHeader) error
Validate
Satisfies the Library to see if the media item passed is valid. It will check if the file is a valid mime type, if the file size is less than the size specified in the options and finally checks the image boundaries.
Returns errors.INVALID any of the conditions fail.