Documentation ¶
Index ¶
- Constants
- Variables
- func Check(mdata Metadata, f File) (map[string]string, error)
- func IsOfType(mdata Metadata, typ string) bool
- func RegisterHandler(mh Handler)
- func TypeOf(mdata Metadata) string
- func WalkContent(f File, walkFn WalkFunc) error
- type File
- type Handler
- type Handlers
- type Metadata
- type WalkFunc
Constants ¶
const ( // TypeField is the name of the field that contains the type of the media TypeField = "Type" // DefaultType is the name used by default to identify a media type. // It is usually used in case media cannot be identified (either missing // or incorrect value) DefaultType = "media" )
const ( // DefaultMimetype is the fallback content type to identify file. The // handler that supports DefaultMimetype, if any, is also the default // handler should no handler be registered for a given Type or Mimetype. DefaultMimetype = "application/octet-stream" )
Variables ¶
var ( // ErrNoMetadataFound reports an error when no Metadata found ErrNoMetadataFound = errors.New("media: no metadata found") )
var ( // ErrUnknownMediaType error is raise if submitted file is of unknown media // type, that is to say that no corresponding media handler is found. ErrUnknownMediaType = fmt.Errorf("media handler: unknown file type") )
Functions ¶
func Check ¶ added in v0.7.0
Check reviews a media metadata and content to capture possible quality issues. Quality issues are organised by Metadata Field using "Content" as the special field name for issues about the media.File content itself.
func IsOfType ¶ added in v0.3.3
IsOfType checks whether the media is of the given type. IsOfType considers media's type of the form "family/sub-family" and checks if the provided type name is either the complete type, only the family of the sub-family.
func RegisterHandler ¶
func RegisterHandler(mh Handler)
RegisterHandler registers a new media handler. It does not check if the handler is already registered.
func TypeOf ¶ added in v0.3.3
TypeOf returns the media's type corresponding to the TypeField attribute value. If no information exists for TypeField attribute or if it is not of the appropriate type, it feedbacks DefaultType
func WalkContent ¶ added in v0.7.0
WalkContent walks the media.File content, calling for each media.File sub-set the provided WalkFunc.
Types ¶
type Handler ¶
type Handler interface { // Type provides the name of the handler. An handler's name is mainly used // to identify a media type and adopt customized behavior based on a media // type. Type() string // Mimetype provides the mimetype that the handler can manage. Mimetype() string // ReadMetadata retrieves the metadata from a given file. ReadMetadata(File) (Metadata, error) // FetchMetadata retrieves the metadata from an external source (usually an // internet data base) that corresponds to the provided known data. FetchMetadata(Metadata) ([]Metadata, error) // Check reviews a media's metadata and content to capture possible quality // issues. Quality issues are organised by Metadata Field using "Content" // as the special field name for issues about the media.File content // itself. Check(Metadata, File) (map[string]string, error) // WalkContent walks the media.File content, calling for each // media.File sub-set the provided WalkFunc. WalkContent(File, WalkFunc) error }
Handler represents a media handler.
type Handlers ¶
type Handlers []Handler
Handlers represent the list of known media handlers.
func (Handlers) ForMetadata ¶ added in v0.4.0
ForMetadata retrieves the handler corresponding to the provided metadata. Should no registered handler be found, the handler for DefaultType is returned if it exists.
ErrUnknownMediaType is returned if no handler is found.
func (Handlers) ForMimetype ¶
ForMimetype retrieves the handler corresponding to the provided mimetype. Should no registered handler be found, the handler for DefaultType is returned if it exists.
ErrUnknownMediaType is returned if no handler is found.
type Metadata ¶
type Metadata = map[string]interface{}
Metadata represents a set of media's metadata, it is essentially a set of (key, value).
func FetchMetadata ¶
FetchMetadata retrieves the metadata from an external source (usually an internet data base) that corresponds to the provided known data.
func ReadMetadata ¶ added in v0.4.0
ReadMetadata reads metadata from the provided File and setup the proper media Type if not done by the corresponding Handler.
func ReadMetadataFromFile ¶ added in v0.4.0
ReadMetadataFromFile reads metadata from the provided file name.