media: github.com/qor/media Index | Files | Directories

package media

import "github.com/qor/media"

Index

Package Files

base.go callback.go handlers.go media.go utils.go

Variables

var (
    // set MediaLibraryURL to change the default url /system/{{class}}/{{primary_key}}/{{column}}.{{extension}}
    MediaLibraryURL = ""
)

func IsImageFormat Uses

func IsImageFormat(name string) bool

IsImageFormat check filename is image or not

func IsSVGFormat Uses

func IsSVGFormat(name string) bool

func IsVideoFormat Uses

func IsVideoFormat(name string) bool

IsVideoFormat check filename is video or not

func RegisterCallbacks Uses

func RegisterCallbacks(db *gorm.DB)

RegisterCallbacks register callback into GORM DB

func RegisterMediaHandler Uses

func RegisterMediaHandler(name string, handler MediaHandler)

RegisterMediaHandler register Media library handler

type Base Uses

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"`
    // contains filtered or unexported fields
}

Base defined a base struct for storages

func (Base) ConfigureQorMetaBeforeInitialize Uses

func (Base) ConfigureQorMetaBeforeInitialize(meta resource.Metaor)

ConfigureQorMetaBeforeInitialize configure this field for Qor Admin

func (*Base) Cropped Uses

func (b *Base) Cropped(values ...bool) (result bool)

Cropped mark the image to be cropped

func (Base) Ext Uses

func (b Base) Ext() string

func (*Base) GetCropOption Uses

func (b *Base) GetCropOption(name string) *image.Rectangle

GetCropOption get crop options

func (Base) GetFileHeader Uses

func (b Base) GetFileHeader() FileHeader

GetFileHeader get file's header, this value only exists when saving files

func (Base) GetFileName Uses

func (b Base) GetFileName() string

GetFileName get file's name

func (Base) GetSizes Uses

func (b Base) GetSizes() map[string]*Size

GetSizes get configured sizes, it will be used to crop images accordingly

func (Base) GetURL Uses

func (b Base) GetURL(option *Option, scope *gorm.Scope, field *gorm.Field, templater URLTemplater) string

GetURL get default URL for a model based on its options

func (Base) GetURLTemplate Uses

func (b Base) GetURLTemplate(option *Option) (path string)

GetURLTemplate get url template

func (Base) IsImage Uses

func (b Base) IsImage() bool

IsImage return if it is an image

func (Base) IsSVG Uses

func (b Base) IsSVG() bool

func (Base) IsVideo Uses

func (b Base) IsVideo() bool

func (*Base) NeedCrop Uses

func (b *Base) NeedCrop() bool

NeedCrop return the file needs to be cropped or not

func (Base) Retrieve Uses

func (b Base) Retrieve(url string) (*os.File, error)

Retrieve retrieve file content with url

func (*Base) Scan Uses

func (b *Base) Scan(data interface{}) (err error)

Scan scan files, crop options, db values into struct

func (Base) String Uses

func (b Base) String() string

String return file's url

func (Base) URL Uses

func (b Base) URL(styles ...string) string

URL return file's url with given style

func (Base) Value Uses

func (b Base) Value() (driver.Value, error)

Value return struct's Value

type CropOption Uses

type CropOption struct {
    X, Y, Width, Height int
}

CropOption includes crop options

type FileHeader Uses

type FileHeader interface {
    Open() (multipart.File, error)
}

FileHeader is an interface, for matched values, when call its `Open` method will return `multipart.File`

type FileInterface Uses

type FileInterface interface {
    io.ReadSeeker
    io.Closer
}

FileInterface media file interface

type Media Uses

type Media interface {
    Scan(value interface{}) error
    Value() (driver.Value, error)

    GetURLTemplate(*Option) string
    GetURL(option *Option, scope *gorm.Scope, field *gorm.Field, templater URLTemplater) string

    GetFileHeader() FileHeader
    GetFileName() string

    GetSizes() map[string]*Size
    NeedCrop() bool
    Cropped(values ...bool) bool
    GetCropOption(name string) *image.Rectangle

    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 Uses

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 Option Uses

type Option map[string]string

Option media library option

func (Option) Get Uses

func (option Option) Get(key string) string

get option with name

func (Option) Set Uses

func (option Option) Set(key string, val string)

set option

type Size Uses

type Size struct {
    Width   int
    Height  int
    Padding bool
}

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 Uses

type URLTemplater interface {
    GetURLTemplate(*Option) string
}

URLTemplater is a interface to return url template

Directories

PathSynopsis
asset_manager
filesystem
media_library
oss

Package media imports 31 packages (graph) and is imported by 20 packages. Updated 2019-03-18. Refresh now. Tools for package owners.