Documentation ¶
Index ¶
- Variables
- func ByteCountSI(b int) string
- func GetImageFormat(url string) (*imaging.Format, error)
- func IsImageFormat(name string) bool
- func IsSVGFormat(name string) bool
- func IsVideoFormat(name string) bool
- func RegisterMediaHandler(name string, handler MediaHandler)
- func SaveUploadAndCropImage(db *gorm.DB, obj interface{}) (err error)
- func SetFileSizes(media Media, fileSizes map[string]int)
- func SetWeightHeight(media Media, width, height int)
- type Base
- func (b *Base) Cropped(values ...bool) (result bool)
- func (b Base) Ext() string
- func (b *Base) GetCropOption(name string) *image.Rectangle
- func (b Base) GetFileHeader() FileHeader
- func (b Base) GetFileName() string
- func (b *Base) GetFileSizes() map[string]int
- func (b Base) GetSizes() map[string]*Size
- func (b Base) GetURL(option *Option, db *gorm.DB, field *schema.Field, templater URLTemplater) string
- func (b Base) GetURLTemplate(option *Option) (path string)
- func (b Base) IsImage() bool
- func (b Base) IsSVG() bool
- func (b Base) IsVideo() bool
- func (b *Base) NeedCrop() bool
- func (b Base) Retrieve(url string) (*os.File, error)
- func (b *Base) Scan(data interface{}) (err error)
- func (b Base) String() string
- func (b Base) URL(styles ...string) string
- func (b Base) Value() (driver.Value, error)
- type CropOption
- type FileHeader
- type FileInterface
- type Media
- type MediaHandler
- type Option
- type Size
- type URLTemplater
Constants ¶
This section is empty.
Variables ¶
var DefaultSizeKey = "default"
var (
// set MediaLibraryURL to change the default url /system/{{class}}/{{primary_key}}/{{column}}.{{extension}}
MediaLibraryURL = ""
)
Functions ¶
func ByteCountSI ¶
func IsImageFormat ¶
IsImageFormat check filename is image or not
func IsSVGFormat ¶
func IsVideoFormat ¶
IsVideoFormat check filename is video or not
func RegisterMediaHandler ¶
func RegisterMediaHandler(name string, handler MediaHandler)
RegisterMediaHandler register Media library handler
func SaveUploadAndCropImage ¶
func SetFileSizes ¶
func SetWeightHeight ¶
Types ¶
type Base ¶
type Base struct { FileName string Url string CropOptions map[string]*CropOption `json:",omitempty"` Delete bool `json:"-"` Crop bool `json:"-"` FileHeader FileHeader `json:"-"` Reader io.Reader `json:"-"` Options map[string]string `json:",omitempty"` Width int `json:",omitempty"` Height int `json:",omitempty"` FileSizes map[string]int `json:",omitempty"` // contains filtered or unexported fields }
Base defined a base struct for storages
func (*Base) GetCropOption ¶
GetCropOption get crop options
func (Base) GetFileHeader ¶
func (b Base) GetFileHeader() FileHeader
GetFileHeader get file's header, this value only exists when saving files
func (*Base) GetFileSizes ¶
GetFileSizes get file sizes
func (Base) GetURL ¶
func (b Base) GetURL(option *Option, db *gorm.DB, field *schema.Field, templater URLTemplater) string
GetURL get default URL for a model based on its options
func (Base) GetURLTemplate ¶
GetURLTemplate get url template
type CropOption ¶
type CropOption struct {
X, Y, Width, Height int
}
CropOption includes crop options
type FileHeader ¶
FileHeader is an interface, for matched values, when call its `Open` method will return `multipart.File`
type FileInterface ¶
type FileInterface interface { io.ReadSeeker io.Closer }
FileInterface media file interface
type Media ¶
type Media interface { Scan(value interface{}) error Value() (driver.Value, error) GetURLTemplate(*Option) string GetURL(option *Option, db *gorm.DB, field *schema.Field, templater URLTemplater) string GetFileHeader() FileHeader GetFileName() string GetSizes() map[string]*Size NeedCrop() bool Cropped(values ...bool) bool GetCropOption(name string) *image.Rectangle GetFileSizes() map[string]int Store(url string, option *Option, reader io.Reader) error Retrieve(url string) (FileInterface, error) IsImage() bool URL(style ...string) string Ext() string String() string }
Media is an interface including methods that needs for a media library storage
type MediaHandler ¶
type MediaHandler interface { CouldHandle(media Media) bool Handle(media Media, file FileInterface, option *Option) error }
MediaHandler media library handler interface, defined which files could be handled, and the handler
type Size ¶
Size is a struct, used for `GetSizes` method, it will return a slice of Size, media library will crop images automatically based on it
type URLTemplater ¶
URLTemplater is a interface to return url template