Documentation
¶
Index ¶
- Constants
- Variables
- func ContainsGuesser(mimeType string, contains [][]byte) func(filename string, data []byte) string
- func ExtensionGuesser(m map[string]string) func(filename string, data []byte) string
- func Guess(filename string, data []byte) string
- func LocalDatabaseGuesser(filename string, data []byte) string
- func PlaintextGuesser(filename string, data []byte) string
- func With(guesser ...GuesserFunc)
- type Guesser
- type GuesserFunc
Constants ¶
const NO_MIME string = ""
Variables ¶
var DefaultMimetypeMap = map[string]string{
"html": "text/html",
"htm": "text/html",
"txt": "text/plain",
"css": "text/css",
"csv": "text/csv",
"js": "application/javascript",
"json": "application/json",
"xml": "application/xml",
"gif": "image/gif",
"jpeg": "image/jpeg",
"jpg": "image/jpeg",
"png": "image/png",
"svg": "image/svg+xml",
"ico": "image/x-icon",
"webp": "image/webp",
"mp4": "video/mp4",
"webm": "video/webm",
"pdf": "application/pdf",
"zip": "application/zip",
"gz": "application/gzip",
"tar": "application/x-tar",
"7z": "application/x-7z-compressed",
"rar": "application/x-rar-compressed",
"bz2": "application/x-bzip2",
"mp3": "audio/mpeg",
"wav": "audio/wav",
"ogg": "audio/ogg",
"flac": "audio/flac",
"mpg": "video/mpeg",
"mpeg": "video/mpeg",
"mov": "video/quicktime",
"avi": "video/x-msvideo",
"wmv": "video/x-ms-wmv",
}
Functions ¶
func ContainsGuesser ¶
ContainsGuesser returns a guesser function that will check if the data contains any of the given byte slices
If it does, it will return the given mimetype
func ExtensionGuesser ¶ added in v1.0.1
ExtensionGuesser returns a guesser function that will check if the filename ends with the given extension. If it does, it will return the given mimetype.
This function takes a map of extensions to mimetypes
func Guess ¶
Guess returns the mime type of the given data
Otherwise return "application/octet-stream"
func LocalDatabaseGuesser ¶
Check for signatures of known mimetypes in the data
func PlaintextGuesser ¶
PlaintextGuesser returns a guesser function that will check if the data is ascii or unicode
If it is ascii, it will return "text/plain; charset=utf-8"
If it is unicode, it will return "text/plain; charset=utf-16"
Types ¶
type Guesser ¶
type Guesser struct {
Funcs []GuesserFunc
}
func (*Guesser) Guess ¶
Guess returns the mime type of the given data
Otherwise return "application/octet-stream"
func (*Guesser) With ¶
func (g *Guesser) With(guesser ...GuesserFunc)