Documentation
¶
Overview ¶
Package mime provides mime type system utilities
Index ¶
- Constants
- func FromPathOnly(path string) (mime string)
- func GetCharset(mime string) (charset string, ok bool)
- func GetExtension(extension string) (mime string, ok bool)
- func IsPlainText(mime string) (yes bool)
- func Mime(path string) (mime string)
- func PlainTextDetector(raw []byte, limit uint32) bool
- func PruneCharset(mime string) (pruned string)
- func RegisterTextType(mime, extension string, detector func(raw []byte, limit uint32) bool) (err error)
- func SetCharset(mime, charset string)
- func SetExtension(extension, mime string)
Constants ¶
const ( TextMimeType = "text/plain" HtmlMimeType = "text/html" CssMimeType = "text/css" ScssMimeType = "text/x-scss" JsonMimeType = "application/json" JavaScriptMimeType = "text/javascript" BinaryMimeType = "application/octet-stream" // DirectoryMimeType defines the mime type used for filesystem directories DirectoryMimeType = "inode/directory" // EnjinMimeType defines the mime type for the Go-Enjin project's `njn` // page format EnjinMimeType = "text/enjin" // OrgModeMimeType defines the mime type used by the Go-Enjin project to // identify the `org-mode` page format OrgModeMimeType = "text/org-mode" // MarkdownMimeType defines the mime type used by the Go-Enjin project to // identify the `markdown` page format MarkdownMimeType = "text/markdown" )
const ( // EnjinExtension defines the file extension associated with the // EnjinMimeType EnjinExtension = "njn" // OrgModeExtension defines the file extension associated with the // OrgModeMimeType OrgModeExtension = "org" // MarkdownExtension defines the file extension associated with the // MarkdownMimeType MarkdownExtension = "md" )
Variables ¶
This section is empty.
Functions ¶
func FromPathOnly ¶
FromPathOnly checks the given `path` for any extensions using github.com/go-corelibs/path.ExtExt and uses GetExtension with any extensions found
func GetCharset ¶
GetCharset returns the `charset` internally associated with this package
func GetExtension ¶
GetExtension returns the mime type internally associated with this package using SetExtension, or if not present uses mime.TypeByExtension to lookup further
func IsPlainText ¶
IsPlainText returns true if the given `mime` is of `text/plain` type. IsPlainText checks if it has an internally registered charset first and if so, returns true early. If the `mime` is not internally registered with a charset (via SetCharset), IsPlainText uses github.com/gabriel-vasile/mimetype.Lookup to check if the given `mime` is exactly TextMimeType or if any of the found mime type's parents are TextMimeType
func Mime ¶
Mime returns the MIME type string of a local filesystem directory or file. The specific type returned for directories is defined by the DirectoryMimeType constant
func PlainTextDetector ¶
PlainTextDetector is the default detector used when RegisterTextType is given a `nil` value for it's `detector` argument. PlainTextDetector always returns true
func PruneCharset ¶
PruneCharset uses mime.ParseMediaType to parse the given mime string and returns only the media type value
func RegisterTextType ¶
func RegisterTextType(mime, extension string, detector func(raw []byte, limit uint32) bool) (err error)
RegisterTextType associates the given `mime` with the given `extension` and if the `detector` is not nil, registers the given `mime` with TextMimeType as it's parent within the github.com/gabriel-vasile/mimetype system
func SetCharset ¶
func SetCharset(mime, charset string)
SetCharset registers the given extension with the given charset string. There can only be one charset associated per extension and SetCharset will overwrite any existing value
func SetExtension ¶
func SetExtension(extension, mime string)
SetExtension registers the given extension with the given mime type string. There can only be one mime type associated per extension and SetExtension will overwrite any existing value. If `mime` is empty, any internal association with the extension is cleared
Types ¶
This section is empty.