Documentation
¶
Index ¶
- Constants
- Variables
- func GetImageFormat(url string) (*imaging.Format, error)
- func Handle(media Media, cb func(name string, handle MediaHandler) error) (err error)
- func IgnoreCallback(db *aorm.DB) *aorm.DB
- func IsIgnoreCallback(v interface{}) bool
- func IsImageFormat(name string) bool
- func IsSVGFormat(name string) bool
- func IsVideoFormat(name string) bool
- func MediaHandlers() map[string]MediaHandler
- func MediaStyleURL(url, style string) string
- func MediaURL(base string, parts ...string) string
- func RegisterCallbacks(db *aorm.DB)
- func RegisterMediaHandler(name string, handler MediaHandler)
- func VideoFormats() []string
- type AcceptExts
- type AcceptTypes
- type Base
- func (b *Base) AfterScan(db *aorm.DB, field *aorm.Field)
- func (b *Base) AllNames(m Media) []string
- func (Base) AormDataType(dialect aorm.Dialector) string
- func (Base) ConfigureQorMetaBeforeInitialize(meta resource.Metaor)
- func (b *Base) ContextScan(ctx *core.Context, data interface{}) (err error)
- func (b Base) DBValue(media Media) (driver.Value, error)
- func (b Base) Deletable() bool
- func (b Base) Ext() string
- func (b *Base) FieldOption() *Option
- func (b Base) FullURL(ctx *core.Context, styles ...string) (url string)
- func (b Base) FullURLU(ctx *core.Context, styles ...string) (url string)
- func (b Base) GetFileHeader() FileHeader
- func (b Base) GetFileName() string
- func (b *Base) GetOrSetFieldOption() *Option
- func (b Base) GetURL(scope *aorm.Scope, field *aorm.Field, templater URLTemplater) string
- func (b Base) GetURLTemplate(option *Option) (path string)
- func (b Base) HasFile() bool
- func (b *Base) Init(site *core.Site, field *aorm.Field)
- func (b Base) IsImage() bool
- func (b Base) IsSVG() bool
- func (b Base) IsVideo() bool
- func (b Base) IsZero() bool
- func (b *Base) MediaScan(ctx *Context, data interface{}) (err error)
- func (b *Base) Names() (names []string)
- func (b *Base) OlderURL() []string
- func (b *Base) Remove(url string) (found bool, err error)
- func (b *Base) RemoveAll(media Media) (found bool, err error)
- func (b Base) Retrieve(url string) (*os.File, error)
- func (b *Base) Scan(data interface{}) (err error)
- func (b *Base) ScanBytes(ctx *Context, data []byte) (err error)
- func (b *Base) Set(ctx *Context, data interface{}) (err error)
- func (b *Base) SetFieldOption(option *Option)
- func (b *Base) SetSite(site *core.Site)
- func (b *Base) SetStorage(storage oss.NamedStorageInterface)
- func (b *Base) Site() *core.Site
- func (b *Base) Storage() oss.NamedStorageInterface
- func (b *Base) Store(url string, reader io.Reader) error
- func (b Base) String() string
- func (b *Base) SystemNames() (names []string)
- func (b Base) URL(styles ...string) string
- func (b Base) Value() (driver.Value, error)
- type Context
- type FileHeader
- type FullURL
- type FullURLContext
- type FullURLContextStyle
- type FullURLStyle
- type MaxSize
- type Media
- type MediaHandler
- type Option
- func (option Option) Get(key string) string
- func (option *Option) GetPrefix(prefix string) map[string]string
- func (option *Option) Merge(m ...map[string]string) *Option
- func (option *Option) MergePrefix(prefix string, m ...map[string]string) *Option
- func (option *Option) ParseFieldTag(tagName string, tag *reflect.StructTag) *Option
- func (option *Option) ParseTagPrefix(prefix, tag string) *Option
- func (option *Option) Set(key, value string) *Option
- func (option *Option) SetDefault(key, value string) *Option
- type Plugin
- type URL
- type URLContext
- type URLContextStyle
- type URLStyle
- type URLTemplater
Constants ¶
const ( FIELD_TAG_NAME = "media" OPT_STORAGE = FIELD_TAG_NAME + ".storage" )
Variables ¶
var ( PKG = path_helpers.GetCalledDir() I18NGROUP = i18nmod.PkgToGroup(PKG) )
var DB_DELETE_IGNORE = PKG + ".delete.ignore"
var E_DELETE = PKG + ":delete"
var (
// URLTemplate default URL template
URLTemplate = "/system/{{class}}/{{primary_key_path}}/{{column}}/{{filename_slug}}"
)
Functions ¶
func IsIgnoreCallback ¶
func IsIgnoreCallback(v interface{}) bool
func IsImageFormat ¶
IsImageFormat check filename is image or not
func IsSVGFormat ¶
func IsVideoFormat ¶
IsVideoFormat check filename is video or not
func MediaHandlers ¶
func MediaHandlers() map[string]MediaHandler
func MediaStyleURL ¶
func RegisterCallbacks ¶
RegisterCallbacks register callback into GORM DB
func RegisterMediaHandler ¶
func RegisterMediaHandler(name string, handler MediaHandler)
RegisterMediaHandler register Media library handler
func VideoFormats ¶
func VideoFormats() []string
Types ¶
type AcceptExts ¶
type AcceptExts interface {
FileExts() []string
}
type AcceptTypes ¶
type AcceptTypes interface {
FileTypes() []string
}
type Base ¶
type Base struct { FileName string Url string FileSize int64 Delete bool `json:"-"` FileHeader FileHeader `json:"-"` Reader io.Reader `json:"-"` // contains filtered or unexported fields }
Base defined a base struct for storages
func (Base) ConfigureQorMetaBeforeInitialize ¶
ConfigureQorMetaBeforeInitialize configure this field for Qor Admin
func (*Base) ContextScan ¶
func (*Base) FieldOption ¶
func (Base) GetFileHeader ¶
func (b Base) GetFileHeader() FileHeader
GetFileHeader get file's header, this value only exists when saving files
func (*Base) GetOrSetFieldOption ¶
func (Base) GetURLTemplate ¶
GetURLTemplate get url template
func (*Base) SetFieldOption ¶
func (*Base) SetStorage ¶
func (b *Base) SetStorage(storage oss.NamedStorageInterface)
func (*Base) Storage ¶
func (b *Base) Storage() oss.NamedStorageInterface
func (*Base) SystemNames ¶
type Context ¶
type Context struct { Media Media Data []map[interface{}]interface{} }
func NewContext ¶
type FileHeader ¶
FileHeader is an interface, for matched values, when call its `Open` method will return `multipart.File`
type FullURLContext ¶
type FullURLContextStyle ¶
type FullURLStyle ¶
type Media ¶
type Media interface { IsZero() bool HasFile() bool sql.Scanner Site() *core.Site SetSite(site *core.Site) Storage() oss.NamedStorageInterface SetStorage(storage oss.NamedStorageInterface) Init(site *core.Site, field *aorm.Field) FieldOption() *Option SetFieldOption(option *Option) Set(ctx *Context, data interface{}) (err error) Value() (driver.Value, error) GetURL(scope *aorm.Scope, field *aorm.Field, templater URLTemplater) string GetFileHeader() FileHeader GetFileName() string Store(url string, reader io.Reader) error Retrieve(url string) (*os.File, error) Remove(url string) (found bool, err error) RemoveAll(m Media) (found bool, err error) ScanBytes(ctx *Context, data []byte) error IsImage() bool GetURLTemplate(option *Option) string URL(style ...string) string FullURL(ctx *core.Context, style ...string) string Ext() string String() string Names() []string SystemNames() []string AllNames(m Media) []string MediaScan(ctx *Context, data interface{}) (err error) OlderURL() []string Deletable() bool }
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 multipart.File, option *Option) error }
MediaHandler media library handler interface, defined which files could be handled, and the handler
type Option ¶
Option media library option
func ParseTagOption ¶
func (*Option) MergePrefix ¶
MergePrefix used to merge options map with prefix
func (*Option) ParseFieldTag ¶
ParseFieldTag used to parse field tag with prefix
func (*Option) ParseTagPrefix ¶
ParseTagPrefix used to parse field tag with prefix
func (*Option) SetDefault ¶
SetDefault used to set default option with name
type Plugin ¶
type Plugin struct { db.DBNames plug.EventDispatcher }
func (*Plugin) OnRegister ¶
func (p *Plugin) OnRegister()
type URLContext ¶
type URLContextStyle ¶
type URLTemplater ¶
URLTemplater is a interface to return url template